Explore Connect Documentation
Snippets
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
#include <iostream>
using namespace std;
int factorial(int n) {
  cout << "entering factorial(" << n << ')' << endl;
  
  if (n == 1) {
    cout << "leaving factorial(1) with return value 1" << endl;
    
    return 1;
  }
  
  int result = n * factorial(n - 1);
  cout << "leaving factorial(" << n <<
    ") with return value " << result << endl;
  
  return result;
}
int main() {
  cout << factorial(3) << endl;
  
  return 0;
}
Press desired key combination and then press ENTER.