lesson 9 add1 100 c
[[lesson_9_add1_100_c]] last edit on
Aug 10, 2005
3:48 AM
by rescued_by_c
[user02@FC4 Lesson09]$ cat -n add1_100.c
[user02@FC4 Lesson09]$ ./add1_100
Adding 1 to 0 yields 1
Adding 2 to 1 yields 3
Adding 3 to 3 yields 6
Adding 4 to 6 yields 10
.....
Adding 97 to 4656 yields 4753
Adding 98 to 4753 yields 4851
Adding 99 to 4851 yields 4950
Adding 100 to 4950 yields 5050
1 #include <stdio.h>
2
3 int main(void)
4 {
5 int count;
6 int total = 0;
7
8 for (count = 1; count <= 100; count++)
9 {
10 printf("Adding %d to %d", count, total);
11 total = total + count;
12 printf(" yields %d\n", total);
13 }
14
15 return 0;
16 }
[user02@FC4 Lesson09]$ gcc -o add1_100 add1_100.c[user02@FC4 Lesson09]$ ./add1_100
Adding 1 to 0 yields 1
Adding 2 to 1 yields 3
Adding 3 to 3 yields 6
Adding 4 to 6 yields 10
.....
Adding 97 to 4656 yields 4753
Adding 98 to 4753 yields 4851
Adding 99 to 4851 yields 4950
Adding 100 to 4950 yields 5050