### Recursion

Hi hello ,
Im just new to c++
and im using turbo c++ 4.5 or borland c++ 4.5
as i want to learn first the old one before the new one ( i dont know why)
______________________________________________________________________________

Now I'm Making Trouble with this Project of mine
Using Recursion to find the sum of 10 numbers
e.g: 1+2+3+4+5+6+7+8+9+10 = 55
i can only make iterative using looping statements.
Merry Christmas and Happy New Year! :)
The trick to understanding recursion is that you must first understand recursion.
Uhm Can you Show me some codes of it?
Not all just a bit so i can understand the Logic behind it? :)
Thanks :)
 ``12345678910111213141516`` ``````#include int Factorial(int n) { if (n > 1) return n * Factorial (n - 1); else return 1; } int main() { int n = 5; std::cout << n << "! = " << Factorial(n); return 0; }`````` `5! = 120`
In fact iteration is the same as recursion but has a condensed form.:)
If you emulate the stack...

 ``1234567891011`` ``````void paint(int row, int col, int key, int colour){ //key not_eq colour if( map[row][col] not_eq key ) //base case (centinels return; map[row][col] = colour; //recursion paint(row+1, col, key, colour); paint(row, col+1, key, colour); paint(row-1, col, key, colour); paint(row, col-1, key, colour); }``````

Now suppose that the recursive calls does execute simultaneously.*
The order would be O( lg n ).

* By instance the processor is a bacteria, at the recursion point it performs mitosis.

Edit: changed the example
Last edited on
Topic archived. No new replies allowed.