0
Trying to add elements in an array in C
Hey so I'm trying to create a program that get 3 numbers from the user and then sum all those numbers up, I'm trying to put all three number into an array and then add them up. This is what I have but it outputting a wrong sum int main (void) { char Numinput[2]; int sum = 0, i; printf("Type three digits: \n"); scanf("%s",Numinput); //printf( "%s\n",Numinput); for (i = 0; i < 3; i++) { sum = sum + Numinput[i]; } printf("sum = %d", sum); }
2 Antworten
+ 4
I made some changes to your code. Hope it helps you.
https://code.sololearn.com/ct95DqxMQlGQ/?ref=app
+ 1
Ur giving only one input in scanf... U should give 3 inputs