Answers for "n factorial c++"

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
0

fcatorianls c++

#include <iostream> 

//n! = n(n-1)!
int factorial (int n)
{
  if (n ==0)
  {
    return 1; 
  }
  else 
  {
	return n * factorial(n-1); 
  }
}
Posted by: Guest on October-21-2020

Browse Popular Code Answers by Language