lesson 9 add1 100 cpp
[[lesson_9_add1_100_cpp]] last edit on Aug 10, 2005 3:44 AM by rescued_by_c

[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