// Program 5: SumOfIntegers.C // (c) Burt Rosenberg 1996 // This program introduces the use of multiple parameters to a function #include void sumInteger ( // Create the function object int sum, int k ) // and two integer objects, initialize the // integer objects. { if ( k==0 ) { // the sum has been fully calculated cout << "Sum is " << sum << endl ; } else { // the sum so far is in sum, add k to it and recurse sumInteger( sum+k, k-1 ) ; } } void main() { int i ; // Get input cout << "Enter i: " ; cin >> i ; // Check for valid input if ( i<0 ) { cout << "Error: i must be positive" << endl ; return ; } // Calculate and print the sum of integer from 0 to i. sumInteger(0,i) ; }