RECURSION IN C

Maha



Recursion In C

Recursion is a technique of making a function to call itself. This  provides a way to break complicated problems down into simple problems which are easier to solve. Recursion may be a bit difficult to understand.

For example: 

we can define the operation "find your way home" 

Syntax:

void recursion() 
{
 recursion(); /* function calls itself */
}
 int main() 
{
 recursion();
}


Program:


  #include <stdio.h>
  int sum(int k);
  int main(){
  int result = sum(11);
  printf("%d", result);
  return 0;
  }
  int sum(int k){
  if (k > 0){
   return k + sum(k - 1);
   } 
else {
   return 0; 
   }
 }


Output:


  66





More topic in C

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send