1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// functions/call-order.cpp -- Illustrates order of calls.
// Fred Swartz 2003-09-02
#include <iostream>
using namespace std;
//--------------------------------- prototypes
int even(int a);
int odd(int b);
int ulam(int c);
//--------------------------------- main
int main() {
// What does each statement print?
cout << odd(4) << endl;
cout << (even(2) + odd(3)) << endl; // (Note 1)
cout << ulam(ulam(ulam(5))) << endl; // (Note 2)
}
//---------------------------------- even
int even(int a) {
cout << "even(" << a << ")" << endl;
return a/2;
}
//---------------------------------- odd
int odd(int b) {
cout << "odd(" << b << ")" << endl;
return 3*b + 1;
}
//---------------------------------- ulam
int ulam(int c) {
cout << "ulam(" << c << ")" << endl;
if (c%2 == 0) {
return even(c);
}else{
return odd(c);
}
}
The text from the above example can be selected, copied, and pasted into an editor.
|