Write a program to compute the factorial of a number using recursion. INPUT AND OUTPUT FORMAT: Input consists of an integer. Refer sample input and output for formatting specifications
Answers
Answered by
2
Answer:
its apython program
#factorial of number using recusion
def factorial(n):
if n==1:
return 1
else:
fact=n*factorial(n-1)
return fact
# main
num=int(input("enter the number"))
print(factorial(num))
#hope it helps you
please mark brainliest
Answered by
4
Answer:
#include<iostream>
using namespace std;
int factorial(int n);
int main()
{
int n;
std::cin>>n;
std::cout << "The factorial of "<<n<< " is " <<factorial(n);
return 0;
}
int factorial(int n)
{
if(n > 1)
return n * factorial(n - 1);
else
return 1;
}
Explanation:
all test case passed.
Similar questions