-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactorial-1,2.cpp
64 lines (64 loc) · 1.15 KB
/
Factorial-1,2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
int fact_rec(int);
int fact(int);
using namespace std;
int main()
{
int op, n, f;
cout << "Factorial in 2 Methods:" << endl
<< "1.Recurssion,\t2.Normal" << endl
<< "Choose Your Option:";
cin >> op;
switch (op)
{
case 1:
cout << "Enter Number:" << endl;
cin >> n;
f = fact_rec(n);
break;
case 2:
cout << "Enter Number:" << endl;
cin >> n;
f = fact(n);
break;
default:
cout << "WRONG OPTION!!!" << endl;
system("cls");
main();
}
cout << "Factorial of"
<< "\t" << n << "\t" << f << endl;
return 0;
}
int fact_rec(int n)
{
if (n == 1 || n == 0)
{
return 1;
}
else
{
return n * fact_rec(n - 1);
}
}
int fact(int n)
{
int i, f = 1;
for (i = 1; i <= n; i++)
{
f = f * i;
}
return f;
}
int main()
{
int n = 5, i, j, sum = 0;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
sum = sum + j;
}
}
std::cout << sum;
}