summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/OR_PRACTICAL_C/07_1.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/CONTRIB/OR_PRACTICAL_C/07_1.c')
-rw-r--r--reference/C/CONTRIB/OR_PRACTICAL_C/07_1.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/reference/C/CONTRIB/OR_PRACTICAL_C/07_1.c b/reference/C/CONTRIB/OR_PRACTICAL_C/07_1.c
new file mode 100644
index 0000000..ab87eb1
--- /dev/null
+++ b/reference/C/CONTRIB/OR_PRACTICAL_C/07_1.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+int total; /* total of all the numbers */
+int current; /* current value from the user */
+int counter; /* while loop counter */
+
+char line[80]; /* Line from keyboard */
+
+main() {
+ total = 0;
+
+ counter = 0;
+ while (counter < 5) {
+ (void)printf("Number? ");
+
+ (void)fgets(line, sizeof(line), stdin);
+ (void)sscanf(line, "%d", &current);
+ total += current;
+
+ counter++;
+ }
+ (void)printf("The grand total is %d\n", total);
+ return (0);
+}