// FILE: fig5.15.cc // FINDS AND PRINTS THE SUM OF ALL INTEGERS FROM 1 TO n #include int main () // standard C++ { // Local data ... int n; // last integer to be added to sum int sum; // sum of all integers from 1 to n int i; // loop control variable // Read the last integer. cout << "Enter the last integer in the sum: "; cin >> n; // Find the sum of all the integers from 1 to n inclusive. sum = 0; for (i = 1; i <= n; i++) sum += i; // Print the sum. cout << "The sum is " << sum << "." << endl; return 0; // no errors }