Trying to add elements in an array in C | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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); }

14th Mar 2019, 4:08 PM
Les.lie
2 Answers
+ 4
I made some changes to your code. Hope it helps you. https://code.sololearn.com/ct95DqxMQlGQ/?ref=app
14th Mar 2019, 4:58 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Ur giving only one input in scanf... U should give 3 inputs
14th Mar 2019, 4:51 PM
Kuri
Kuri - avatar