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 factorial(int n)
5{
6 if (n < 0)
7 return (-1); /*Wrong value*/
8 if (n == 0)
9 return (1); /*Wrong value*/
10 else
11 {
12 return (n * factorial(n - 1));
13 }
14}
15
16int main()
17{
18 int number, ans;
19 cin >> number;
20 ans = factorial(number);
21 cout << ans;
22 return 0;
23}
24
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
1#include <iostream>
2
3//n! = n(n-1)!
4int factorial (int n)
5{
6 if (n ==0)
7 {
8 return 1;
9 }
10 else
11 {
12 return n * factorial(n-1);
13 }
14}