-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrecursive_stack.cpp
59 lines (53 loc) · 1.03 KB
/
recursive_stack.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int stk[100];
int s = 100;
int head = 0;
void push(int x){
if(head==s){
cout<<"OverFlow \n";
}
else{
++head;
stk[head] = x;
}
}
int top(){
if(head==0){
cout<<"UnderFlow \n";
return 0;
}
else{
return stk[head];
}
}void pop(){
if(head==0){
cout<<"UnderFlow \n";
}
else{
--head;
}
}
int isempty(){
if(head==-1)
return 1;
else
return 0;
}
int fact(int n){
if (n == 0)
return 1;
else
push(top() * n);
return fact(n-1);
}
int main() {
int n;
cout<<"Enter a Number \n";
scanf("%d", &n);
push(1);
fact(n);
cout<<"Factorial "<<top()<<"\n";
return 0;
}