#include
#include
double arr[40];
int top=-1;
void push(double val)
{
top++;
arr[top]=val;
}
double pop()
{
int a=top;
top--;
return(arr[a]);
}
main()
{
char *postfix;
double a,i,j;
clrscr();
printf("entert postfix expression-> ");
gets(postfix);
for(a=0;postfix[a]!='\0';a++)
{
if(postfix[a]>64&&postfix[a]<91||postfix[a]>96&&postfix[a]<123)
{
gotoxy(5,4);
printf("enter the value of %c -> ",postfix[a]);
scanf("%lf",&i);
push(i);
gotoxy(5,4); printf(" ");
}
else
{
i=pop();
j=pop();
if(postfix[a]=='+')
push(i+j);
else
if(postfix[a]=='-')
push(i-j);
else
if(postfix[a]=='*')
push(i*j);
else
if(postfix[a]=='/')
push(i/j);
else
if(postfix[a]=='^')
push(pow(j,i));
}
}
printf("\n\n\tValue of the expression-> %lf",pop());
getch();
}
0 comments:
Post a Comment