c++ factorial
#include <cmath>
int fact(int n){
return std::tgamma(n + 1);
}
// for n = 5 -> 5 * 4 * 3 * 2 = 120
//tgamma performas factorial with n - 1 -> hence we use n + 1
c++ factorial
#include <cmath>
int fact(int n){
return std::tgamma(n + 1);
}
// for n = 5 -> 5 * 4 * 3 * 2 = 120
//tgamma performas factorial with n - 1 -> hence we use n + 1
recursion factorial algorithm
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 *)
factorial recursive
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))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us