Calling Recursive program

Can't get 30. How this program works?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int mystery (int);

int main ()
{
	int n;
	mystery (4);
	
	return 0;
	
}

int mystery (int n)
{
	if (n==0)
		return 10;
	else 
		return 2 * n + mystery (--n);
}
2 x 4 +(2 x 3 +( 2 x 2 + (2 x 1 + (10))))
becomes:
2 x 4 +(2 x 3 +( 2 x 2 + 12))
becomes:
2 x 4 +(2 x 3 +16)
becomes:
2 x 4 + 22
becomes:
30
Topic archived. No new replies allowed.