Skip to content

Commit 395900a

Browse files
authored
program to find factorial of a given no. without using recursive function.
program to find factorial of a given no. without using recursive function.
1 parent b2f1a2f commit 395900a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

math/C++/factorial.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
//program to find factorial of a given no. using recursive function.
1+
//program to find factorial of a given no. without using recursive function.
22

3-
#include <iostream.h>
3+
#include <iostream>
44
using namespace std;
55
int fac(int n){
6-
if
7-
{
8-
n<=1 return 1;
9-
}
10-
else
11-
{
12-
return n*fac(n-1);
13-
}
6+
int m=1;
7+
for(int j=1; j<=n; j++)
8+
{
9+
m=m*j;
10+
}
11+
return m;
1412
}
1513

1614
int main(){
1715
int i,n;
18-
cout<<"enter the no. for finding the factorial";
16+
cout<<"enter the no. for finding the factorial : \n";
1917
cin>>n;
2018
i=fac(n);
2119
cout<<"the factorial of the given no. is "<<i;

0 commit comments

Comments
 (0)