We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b2f1a2f commit 395900aCopy full SHA for 395900a
math/C++/factorial.cpp
@@ -1,21 +1,19 @@
1
-//program to find factorial of a given no. using recursive function.
+//program to find factorial of a given no. without using recursive function.
2
3
-#include <iostream.h>
+#include <iostream>
4
using namespace std;
5
int fac(int n){
6
-if
7
-{
8
- n<=1 return 1;
9
-}
10
-else
11
12
- return n*fac(n-1);
13
+ int m=1;
+ for(int j=1; j<=n; j++)
+ {
+ m=m*j;
+ }
+ return m;
14
}
15
16
int main(){
17
int i,n;
18
-cout<<"enter the no. for finding the factorial";
+cout<<"enter the no. for finding the factorial : \n";
19
cin>>n;
20
i=fac(n);
21
cout<<"the factorial of the given no. is "<<i;
0 commit comments