recursion

hi everyone...would you plz help me in programming..our topic is about recursion and i find it hard to understand it...would somebody give me simple program about recursion...so that i could understand it easily...(dev c++)...tnx
closed account (z05DSL3A)
[joke]Recursion...here we go again.[/joke]

I did start an article on recursion, it may help. It is unfinished due to lack of time and the death of the PC I was writing it on.

[DRAFT] How To: Recursion
http://www.cplusplus.com/forum/articles/2231/
Here's something else I though was good as well.

http://cis.stvincent.edu/html/tutorials/swd/recur/recur.html
So, here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

void countdown(int n);

int main(){
countdown(4);
cin.get();
}

void countdown(int n){
cout << n << "...\n";
if(n > 0)
countdown(n-1);
cout << "BOOM!\n";}

Note the fact that when it is run with 4, it will do the following:
4...
3...
2...
1...
0...
BOOM!
BOOM!
BOOM!
BOOM!
BOOM!

That's because countdown() created 5 variables all called n. Once the is statement is false, it will back out of the levels of recursion.
Topic archived. No new replies allowed.