[user02@FC4 Lesson09]$ cat -n add1_100.cpp
1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 int count;
7 int total = 0;
8
9 for (count = 1; count <= 100; count++)
10 {
11 cout << "Adding " << count << " to " << total;
12 total = total + count;
13 cout << " yields " << total << endl;
14 }
15
16 return 0;
17 }
[user02@FC4 Lesson09]$ g++ -o add1_100 add1_100.cpp[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 5 to 10 yields 15
.....
Adding 98 to 4753 yields 4851
Adding 99 to 4851 yields 4950
Adding 100 to 4950 yields 5050
lesson_9_add1_100.cpp, Rev. 1, Last changed on 2005-08-10 03:44, 278 page hits