STACK AND ITS APPLICATION


This program converts a decimal number to binary using stacks.


#include"stdio.h"
int *p;
main()
{
int a,b,c,count;
clrscr();
p=malloc(10*sizeof(int));
printf("enter a number:");
scanf("%d",&a);
count=0;
while(a>0)
{
b=a%2;
in(b);
a=a/2;
count++;
}
while(count>0)
{
c=out();
printf("%d",c);
count--;
}
getch();
}

in(int b)
{
*p=b;
p++;
}

out()
{
p--;
return *p;
}

Go to the programs page click here!!

Hosted by www.Geocities.ws

1