forked from sainirock61/CPP-Projects-Algos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathn!.cpp
More file actions
38 lines (27 loc) · 739 Bytes
/
n!.cpp
File metadata and controls
38 lines (27 loc) · 739 Bytes
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
#include<iostream>
using namespace std;
int factorial(int i)
{
if(i>=1)
{
return i*factorial(i-1);
}
else
{
return 1;
}
}
int main()
{
int n;
cout<<"ENTER THE NUMBER TO FIND THE FACTORIAL :-- ";
while(!(cin>>n)|| (n<=0))
{
cin.clear();
cin.ignore(100,'\n');
cout<<" !!!!! INVALID INPUT. ENTER AGAIN :-- ";
}
cout<<"\n===================================================================\n";
cout<<"\n Factorial of "<<n<<" is :-- "<<factorial(n);
cout<<"\n===================================================================\n";
}