home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / for5.cpp < prev    next >
C/C++ Source or Header  |  1993-03-22  |  458b  |  20 lines

  1. // Program calculates a sum of odd integers in 
  2. // the range of 11 to 121
  3.  
  4. #include <iostream.h>
  5.                  
  6. const int FIRST = 11;
  7. const int LAST = 121;                 
  8.                  
  9. main()
  10. {
  11.     double sum = 0;
  12.     for (int i = FIRST; i <= LAST; i += 2) 
  13.       sum += (double)i;
  14.                      
  15.     cout << "Sum of odd integers from "
  16.          << FIRST << " to " << LAST << " = "
  17.          << sum << "\n";
  18.     return 0;
  19. }
  20.