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.
2 parents d104ba0 + c3a80b5 commit 3cc5a27Copy full SHA for 3cc5a27
factorial/cpp/Factorial.cpp
@@ -1,26 +1,17 @@
1
-#include<iostream>
2
-#include<stdio.h>
3
-using namespace std;
4
-
5
-int result[1000] = {0};
6
-long long int fact_dp(int n)
+#include<iostream.h>
+#include<conio.h>
+void main()
7
{
8
- result[0] = 1;
9
- for (int i = 1; i <= n; ++i)
10
- {
11
- result[i] = i * result[i - 1];
12
- }
13
14
- return result[n];
15
-}
16
-int main()
17
-{
18
- int n;
19
- cout<<"Enter a number :";
20
- cin>>n;
21
- if(n<=0)
22
- cout<<1<<endl;
23
- else
24
- cout<<"Factorial :"<<fact_dp(n)<<endl;
25
+ clrscr();
+ long double n,fact=1,num;
+ cout<<"\n\t Enter a number:";
+ cin>>num;
+ n=num;
+ while(num>0)
+ {
+ fact=fact*num;
+ --num;
+ }
+ cout<<"\n\t factorial of "<<n<<" is:"<<fact;
+ getch();
26
}
0 commit comments