i need to write a program instructing users to enter 5 digit integer. and the program must add each integer and sum it for the final result.
for ex 12345 would yield 1+2+3+4+5= 15
when i try using scan f as %d, it reads the ENTIRE 5 digit integer as ONE. when i use %c it calculates a crazy sum for the final answer... here is my work thus far.
Code:
#include <stdio.h>
int main ()
{
;
int num1;
int num2;
int num3;
int num4;
int num5;
printf("enter 5-digit number:");
scanf(" %d%d%d%d%d",&num1,&num2,&num3,&num4,&num5);
sum=num1+num2+num3+num4+num5;
printf("summing %d+%d+%d+%d+%d= %d\n",num1,num2,num3,num4,num5,sum);
return 0;
}