#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;
}
#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
/*#include<bits/stdc++.h>
using namespace std;
iterative solution:
int fact (int n, int k)
{
if(n==0) return 1;
return fact(n-1,k*n);
}
int main()
{
int n,k=1;
cin>>n;
int ans=fact(n,k);
cout<<ans<<endl;
}*/
//recursive solution.
#include<bits/stdc++.h>
using namespace std;
int fact(int n)
{
if(n==0)return 1;
return n*fact(n-1);
}
int main(){
int n;
cin>>n;
cout<<fact(n)<<endl;
}
// C++ program to print all prime factors
#include <bits/stdc++.h>
using namespace std;
// A function to print all prime
// factors of a given number n
void primeFactors(int n)
{
// Print the number of 2s that divide n
while (n % 2 == 0)
{
cout << 2 << " ";
n = n/2;
}
// n must be odd at this point. So we can skip
// one element (Note i = i +2)
for (int i = 3; i <= sqrt(n); i = i + 2)
{
// While i divides n, print i and divide n
while (n % i == 0)
{
cout << i << " ";
n = n/i;
}
}
// This condition is to handle the case when n
// is a prime number greater than 2
if (n > 2)
cout << n << " ";
}
/* Driver code */
int main()
{
int n = 315;
primeFactors(n);
return 0;
}
// This is code is contributed by rathbhupendra