Adds up 5 numbers
#include <stdio.h>
int main() {
int total = 0;
int current;
int counter = 0;
char line[80];
while (counter < 5) {
printf("Number? ");
fgets(line, sizeof(line), stdin);
sscanf(line, "%d", ¤t);
total += current;
++counter;
}
printf("The grand total is %d\n", total);
return (0);
}
Related examples in the same category