#include <stdio.h>
int factorial(int number){
if(number==1){
return number;
}
return number*factorial(number - 1);
}
int main(){
int a=factorial(5);
printf("%d",a);
}
FUNCTION FACTORIAL (N: INTEGER): INTEGER
(* RECURSIVE COMPUTATION OF N FACTORIAL *)
BEGIN
(* TEST FOR STOPPING STATE *)
IF N <= 0 THEN
FACTORIAL := 1
ELSE
FACTORIAL := N * FACTORIAL(N - 1)
END; (* FACTORIAL *)
N= int(input())
def fun(n):
if n ==1 or n==0:
return 1
else:
n = n * fun(n-1)
return n
print(fun(N))
factorial(N){
if(N<=1)
{
return 1;
}
else
{
return (N*factorial(N-1));
}
}
function factorial(n) {
// Base case
if (n === 0 || n === 1) return 1;
// Recursive case
return n * factorial(n — 1);
}
def fact(n):
if n==0 or n==1:
return 1
else:
return n*fact(n-1)
print(fact(4))
print(fact(3))
print(fact(0))
# Factorial of a number using recursion
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
num = 6
# check if the number is negative
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of", num, "is", recur_factorial(num))