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 num; //unsigned is used for not taking negetive values.
7 unsigned long long factorial = 1; //Since the factorial a number can be large, so long long data type is used.
8 cout << "Give me any positive number : ";
9 cin >> num;
10
11 for (int i = 1; i <= num; i++) {
12 factorial = factorial * i;
13 }
14 cout << "Factorial of the given number is: " << factorial;
15}
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}