226k views
2 votes
Write a recursive function using pseudocode or C/C++.

User Mannopson
by
6.7k points

1 Answer

7 votes

Answer:

long fact(int n)

{

if(n<=1)//base case

return 1;

long p=fact(n-1);//recursive call.

return n*p;//returning the factorial.

}

Step-by-step explanation:

Above written function is written in C++ language.It is a recursive function to find the factorial of the function.

If we enter a number equal to or less than 1 then the function returns 1. Then the recursive call is made and it is stored in the long variable p and the result is returned as n*p.

User Mariusnn
by
6.2k points