Friday, August 28, 2009

Evaluation of Expression



#include<stdio.h>



#include<string.h>



#include<ctype.h>



main()



{



char
ans;



do



{



char
postfix[10],x;



int
stack[10],op1,op2;



int
top=-1,i=0;



clrscr();



printf("\n\n\t\t\tEVALUATION
OF EXPRESSION"
);



printf("\n\t\t\t************************");



printf("\n\nENTER
THE POSTFIX EXPRESSION :->"
);



fflush(stdin);



gets(postfix);



x=postfix[i];



while(x!='\0')



{




if
(isdigit(x))



stack[++top]=x-'0';




else



{




op2=stack[top];




op1=stack[top-1];




top--;









if(x=='+')




stack[top]=op1+op2;









else if(x=='-')




stack[top]=op1-op2;









if(x=='*')




stack[top]=op1*op2;









if(x=='/')




stack[top]=op1/op2;



}



x=postfix[++i];



}



printf("\n\nTHE VALUE OF GIVEN EXPRESSION IS :->%d",stack[0]);



printf("\n\nDO U CONTINUE (Y/N):->");



scanf("%s",&ans);



}while(ans=='y'||ans=='y');



getch();



}





No comments:

Post a Comment