< previous page page_1153 next page >

Page 1153
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
        cout << ch;
        if (ch == '\n')
            cout << endl;
        DoubleSpace();
    }
}
4. Rewrite the following PrintSquares function using recursion.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
void PrintSquares()
{
    int count;

    for (count = 1; count <= 10; count++)
        cout << count << ' ' << count * count;
}
5. Modify the Factorial function of this chapter to print its parameter and returned value indented two spaces for each level of call to the function. The call Factorial(3) should produce the following output:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
3
  2
    1
      0
      1
    1
  2
6
6. Write a recursive value-returning function that sums the integers from 1 through N.
7. Rewrite the following function so that it is recursive.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
void PrintSqRoots( /* in */ int n )
{
    int i;

    for (i = n; i > 0; i--)
        cout << i < ' ' << sqrt(double(i)) << endl;
}
8. The RevPrint function of this chapter prints the contents of a dynamic linked list in reverse order. Write a recursive function that prints the contents in forward order.
9. The Print function of this chapter prints the contents of an array from first element to last. Write a recursive function that prints from last element to first.
10. Given the following declarations:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
struct NodeType;
typedef NodeType* PtrType;

 
< previous page page_1153 next page >