< previous page
page_1152
next page >
Page 1152
what is the output of the following program?
#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.
int Func( /* in */ int n )
{
return Func(n - 1) + 3;
}
3. Rewrite the following
DoubleSpace
function without using recursion.
void DoubleSpace( /* inout */ ifstream& inFile )
{
char ch;
inFile.get(ch);
if (inFile) // If not EOF ...
{
< previous page
page_1152
next page >