Answers for "c factorial recursion"

C++
3

find factoril in C using recursion

#include<stdio.h>
fact(int i, int k){
    k=k*i;
    i--;
    if(i==0){
        return k;
    }
    else{
        fact(i, k);
    }
}
int main()
{
    int k = 1, i, factorial;
    scanf("%d",&i);
    factorial = fact(i, k);
    printf("%d\n",factorial);
    return 0;
}
Posted by: Guest on January-31-2021
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

Code answers related to "c factorial recursion"

Browse Popular Code Answers by Language