Horje
c++ factorial Code Example
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
built in factorial function in c++
int factorial(int n)
{
  return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}
FACTORIAL IN C++
#include <iostream>  
using namespace std;  
int main()  
{  
   int i,fact=1,number;    
  cout<<"Enter any Number: ";    
 cin>>number;    
  for(i=1;i<=number;i++){    
      fact=fact*i;    
  }    
  cout<<"Factorial of " <<number<<" is: "<<fact<<endl;  
  return 0;  
}  




Cpp

Related
remove last character from string c++ Code Example remove last character from string c++ Code Example
All data types in C++ Code Example All data types in C++ Code Example
string to char* Code Example string to char* Code Example
delete last char of string C++ Code Example delete last char of string C++ Code Example
priority queue c++ type of pairs Code Example priority queue c++ type of pairs Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7