diff options
Diffstat (limited to 'reference/C/CONTRIB/OR_PRACTICAL_C/07_2.c')
-rw-r--r-- | reference/C/CONTRIB/OR_PRACTICAL_C/07_2.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/reference/C/CONTRIB/OR_PRACTICAL_C/07_2.c b/reference/C/CONTRIB/OR_PRACTICAL_C/07_2.c new file mode 100644 index 0000000..02eedd6 --- /dev/null +++ b/reference/C/CONTRIB/OR_PRACTICAL_C/07_2.c @@ -0,0 +1,20 @@ +#include <stdio.h> + +int total; /* total of all the numbers */ +int current; /* current value from the user */ +int counter; /* for loop counter */ + +char line[80]; /* Input from keyboard */ + +main() { + total = 0; + for (counter = 0; counter < 5; counter++) { + (void)printf("Number? "); + + (void)fgets(line, sizeof(line), stdin); + (void)sscanf(line, "%d", ¤t); + total += current; + } + (void)printf("The grand total is %d\n", total); + return (0); +} |