Recursion in C++

Status
Not open for further replies.

Gizmo

Expert
May 6, 2009
12,863
2
42
Lahore
What exactly are you looking to achieve through recursion?

It's basically when a function keeps calling itself to solve smaller portions of the same problem until a base case is reached.
 

Gizmo

Expert
May 6, 2009
12,863
2
42
Lahore
Code:
int factorial(int x){

   if(x == 1){
    return 1;
   }
   return x * factorial(x-1);
}
^^That's a very basic recursive function that returns the factorial of the argument x.

x==1 is the base case after which recursion ends, until that case is reached the function keeps calling itself with the argument x-1.
 
Status
Not open for further replies.
General chit-chat
Help Users
We have disabled traderscore and are working on a fix. There was a bug with the plugin | Click for Discord
  • No one is chatting at the moment.
    iampasha iampasha: Alan wake 2 is yet to recover it's development costs. Due to no physical release and no steam...