How do we call a C# method recursively?
Answers
Answered by
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:-
- Head recursion
- Tail Recursion
Similar questions
Computer Science,
6 months ago
English,
6 months ago
English,
6 months ago
Math,
1 year ago
English,
1 year ago