I have an assingment of making factorials using stacks..!!
I tried my best but couldn’t make it :/
I copied it from wiki answers but couldn’t get the logic??
and the program is:
#include
#include
int top=0;
void main()
{
int s[10],i,n;
void push(int [30],int);
int pop(int [30]);
void fact(int [10],int);
clrscr();
printf(“Enter: “);
scanf(“%d”,&n);
fact(s,n);
getch();
}
void push(int s[10],int n)
{
if(n>0)
{
top++;
s[top]=n;
push(s,n-1);
}
}
int pop(int s[10])
{
int y;
y=s[top];
top–;
return y;
}
void fact(int s[10],int n)
{
int f=1,i;
push(s,n);
for(i=0;i
f=f*pop(s);
}
printf("\nFactorial of %d = %d",n,f);
}
ok
don't we write prototypes for programes if we want to define function at the end???
and what is happening here??
i mean would somesome please explain how it will work??
and what changes can i make in this program to make sure its not a copy from net???
pushing and poping 0.o
ain't it stacks???

