1#include<bits/stdc++.h>
2#include<stdio.h>
3using namespace std;
4
5int fact(int i){
6 if (i <= 1) return 1;
7 else return i*fact(i-1);
8}
9
10int main(){
11 ios::sync_with_stdio(0);
12 cin.tie(0);
13 int N;
14 cin >> N;
15 cout << fact(N) << "\n";
16 return 0;
17}
1#include <iostream>
2using namespace std;
3
4int main()
5{
6 unsigned int n;
7 unsigned long long factorial = 1;
8
9 cout << "Enter a positive integer: ";
10 cin >> n;
11
12 for(int i = 1; i <=n; ++i)
13 {
14 factorial *= i;
15 }
16
17 cout << "Factorial of " << n << " = " << factorial;
18 return 0;
19}
1#include <cmath>
2
3int fact(int n){
4 return std::tgamma(n + 1);
5}
6// for n = 5 -> 5 * 4 * 3 * 2 = 120
7//tgamma performas factorial with n - 1 -> hence we use n + 1