Explanation of output

I need help with an explanation of how exactly the code works to get the following output, it't a bit confusing.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
using namespace std;

int f1(int a);
int f2(int &a);
int f3(int b);
int f4(int &b);

int main() {
	int a = 1;
	int b = 2;
	int c = f1(a);
	int d = f1(b);
	cout << c << endl;
	cout << d << endl;
	return 0;
}

int f1(int a) {

	if (a == 1) {
		a *= 3;
		cout << a << endl;
		int r = f2(a);
		cout << a << endl;
		return r;
	}
	if (a == 2) {
	a *= 5;
	cout << a << endl;
	return f3(a);
	}
}

int f2(int &a) {
	a += 10;
	int r = f4(a);
	cout << a << endl;
	return r;
}

int f3(int b) {
	b = b % 11;
	int r = f4(b);
	cout << b << endl;
	return r;
}

int f4(int &b) {
	b /= 2;
	cout << b << endl;
	return b;
}


The correct output is as follows:

1
2
3
4
5
6
7
8
9
3
6
6
6
10
5
5
6
5


Can someone explain the math of how each value is outputted. Thank You!
Topic archived. No new replies allowed.