Created
May 16, 2020 05:32
-
-
Save parzibyte/2de350ecd025b8afbb9614bc13b1cfaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
____ _____ _ _ _ | |
| _ \ | __ \ (_) | | | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___ | |
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \ | |
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/ | |
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___| | |
__/ | __/ | | |
|___/ |___/ | |
Blog: https://parzibyte.me/blog | |
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/ | |
Contacto: https://parzibyte.me/blog/contacto/ | |
Copyright (c) 2020 Luis Cabrera Benito | |
Licenciado bajo la licencia MIT | |
El texto de arriba debe ser incluido en cualquier redistribución | |
*/ | |
#include <stdio.h> | |
void imprimir_arreglo(int arreglo[], int longitud) { | |
for (int x = 0; x < longitud; x++) { | |
printf("%d ", arreglo[x]); | |
} | |
} | |
int main() { | |
int arregloA[10] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2}; | |
int arregloB[10] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2}; | |
int arregloC[10];//El resultante | |
// Primero necesitamos la longitud de ambos arreglos. Como tienen la misma longitud, no importa cuál usemos | |
int longitud = sizeof(arregloA) / sizeof(arregloA[0]); | |
// Ahora empezamos un ciclo desde 0 hasta 10, pero tenemos dos contadores | |
// uno nos ayuda a llevar posición del A, y el segundo del B (que irá decrementando) | |
int contadorA = 0; | |
int contadorB = longitud - 1; | |
for (int x = 0; x < longitud; x++) { | |
// Sumamos. Al inicio contadorA estará en 0 y contadorB en 9 | |
int suma = arregloA[contadorA] + arregloB[contadorB]; | |
arregloC[contadorA] = suma; | |
// Avanzar en A y retroceder en B | |
contadorA++; | |
contadorB--; | |
} | |
printf("Arreglo A: "); | |
imprimir_arreglo(arregloA, longitud); | |
printf("\n"); | |
printf("Arreglo B: "); | |
imprimir_arreglo(arregloB, longitud); | |
printf("\n"); | |
printf("Arreglo C: "); | |
imprimir_arreglo(arregloC, longitud); | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment