Computer Science, asked by kumarop8481, 1 year ago

How do we call a C# method recursively?

Answers

Answered by sailorking
0

Recursive function call means calling of a function, by itself repeatedly for completing a specific task. The best example for a recursive method call is, a program of factorial.

void main()

        {      

          int fact=0; int result=0; //variables to store result and input data from user

     cout<< "enter the number" << endl;

     cin>>fact;      //taking the number input for calculating the factorial

     result=factorial(fact);

}

int factorial(int fact)

{

    if ( fact < = 1)      

    {

         return 1;

     }

     else

      {

             return fact*factorial(fact-1);

       }

}

  • There are two types of recursion:-
  1. Head recursion
  2. Tail Recursion
Similar questions