Accept 10 numbers from the user and calculate their sum.
#include <stdio.h>
int main()
{
int i, sum;
printf("Enter 10 numbers: ");
sum = 0;
for(i = 0; i < 10; ++i)
{
int tmp;
if(scanf("%d", &tmp) != 1)
{
printf("Bad input\n");
return 1;
}
sum += tmp;
}
printf("Sum is %d\n", sum);
return 0;
}
Comments
Leave a comment