// SumOfIntegers.C // (c) Burt Rosenberg 1996 // This program introduces the use of multiple parameters to a function #include int 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 return sum ; } else { // the sum so far is in sum, add k to it and recurse return 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. cout << "Sum is " << sumInteger(0,i) << endl ; }