Write C++ function to calculate the factorial value of any integer as an argument.
Source Code:
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
| #include<iostream>
using namespace std;
int factorial(int);
int main()
{
int x,f;
cout<<"Enter number : ";
cin>>x;
f=factorial(x);
cout<<"The factorial is :"<<f;
return 0;
}
int factorial(int a)
{
int fact=1;
while(a>=1)
{
fact=fact*a;
a--;
}
return fact;
}
|

Post a Comment
Click to see the code!
To insert emoticon you must added at least one space before the code.