Lab Program 5 (1)
Lab Program 5 (1)
Design, Develop and Implement a Program in C for the following Stack Applications
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define MAX 50
int stack[MAX];
char post[MAX];
/*fUNCTION PROTOYPE */
void main()
int i;
scanf("%s",post);
for(i=0;i<strlen(post);i++)
1
{
pushstack(i);
calculator(post[i]);
printf("\n\nResult :: %d",stack[top]);
top++;
stack[top]=(int)(post[tmp]-48);
void calculator(char c)
int a,b,ans;
a=stack[top];
stack[top]='\0';
top--;
b=stack[top];
stack[top]='\0';
top--;
switch(c)
2
{
case '+':
ans=b+a;
break;
case '-':
ans=b-a;
break;
case '*':
ans=b*a;
break;
case '/':
ans=b/a;
break;
case '^':
ans=pow(b,a);
break;
default:
ans=0;
top++;
stack[top]=ans;
OUTPUT
3
b. Solving Tower of Hanoi problem with n disks.
#include <stdio.h>
int main()
int num;
scanf("%d", &num);
return 0;
if (num == 1)
return;
printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
4
OUTPUT