The output I expect after reading 3 times is the sum of those three numbers, but when reading the numbers there is a problem with the printing.
for (i = 0; i < TAMANIO; i++) {
scanf("%d\n",&ar[i]);
printf("numero: %d\n",ar[i]); //print numbers
}
If you need full code.
#include <stdio.h>
#define TAMANIO 3
//prototipo de funciones
void pri();
int pro(int a, int b, int c);
int main () {
pri(); //Ask for numbers
int i; //counter
int ar[TAMANIO];
for (i = 0; i < TAMANIO; i++) {
scanf("%d\n",&ar[i]);
printf("numero: %d\n",ar[i]); //print numbers
}
printf("suma de numeros: %d\n", pro(ar[0],ar[1],ar[2])); //send number to function and print
return 0;
}
void pri(){
//write numbers
printf("Escriba los 3 numeros a ser operados : \n");
}
int pro(int a, int b, int c) {
int sum;
sum = a + b + c;
return sum;
}
I expect when reading:
"enter numbers"
1
number : 1
2
number : 2
3
number : 3
sum : 6
[ More Scanf() info ] What is the effect of trailing white space in a scanf() format string?