Answers for "recursive function factorial"

C++
8

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
Posted by: Guest on July-09-2020
2

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 *)
Posted by: Guest on December-29-2020
0

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))
Posted by: Guest on June-26-2021

Code answers related to "recursive function factorial"

Browse Popular Code Answers by Language