< previous page page_1152 next page >

Page 1152
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
what is the output of the following program?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
#include <iostream.h>

void PrintNums();

int main()
{
    PrintNums();
    cout << endl;
    return 0;
}

//***************************************

void PrintNums()
{
    int n;

    cin >> n;
    if (cin)            // If not EOF ...
    {
        cout << n < ' ';
        PrintNums();
        cout << n < ' ';
    }
}
Programming Warm-Up Exercises
1. Write a C++ value-returning function that implements the recursive formula F(N) = F(N-1) + F(N-2) with base cases F(0) = 1 and F(1) = 1.
2. Add whatever is necessary to fix the following function so that Func(3) equals 10.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int Func( /* in */ int n )
{
    return Func(n - 1) + 3;
}
3. Rewrite the following DoubleSpace function without using recursion.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
void DoubleSpace( /* inout */ ifstream& inFile )
{
    char ch;

    inFile.get(ch);
    if (inFile)          // If not EOF ...
    {

 
< previous page page_1152 next page >