recursive function

can anyone tell me what's happen in the recursive function so it appears like this:
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
#include <iostream>
#include <string>
#include <conio.h> 
using namespace std;

int enter, result = 0, k_column;

void reduction () {
	char yn;
	cout << "how many: ";
	cin >> enter;
	for (int i = 0; i <= enter; ++i)
		result += i;

	for (int row = 1; row <= enter; ++row) {
		k_column = enter - row;
		for (int kolom = (enter - row) + 1; kolom > 0; --kolom) {
			cout << result - k_column << " ";
			k_column -= 1;
		}
		result -= (enter - row) + 1;
		cout << endl;
	}
	cout << "again (y/n): ";
	cin >> yn;
	if (yn == 'y')
		reduction();

	//when i press 'n', it appears as much as i press 'y'
	//e.g: if i press 'y' 3 times, it appeared for 3 times, that is:
	//thank you...thank you...thank you...
	//why is that?

	cout << "thank you...";
}

int main() {
	reduction ();
	getch();
	return 0;
}
You call the function three times (recursively or no), so the cout statement at the end is printed three times. It's really that simple. When you call the function recursively, the function that called it isn't ending. It's just waiting until the recursive call is finished, just like any other function call.
Topic archived. No new replies allowed.