Posts

Showing posts from January, 2021

infix to postfix expression converter in "C" language

 program: #include<stdio.h> void infix_to_postfix(char[],char[]); int precedence(char); void main() { char infix[20],postfix[20]; printf("enter infix string : "); scanf("%s",infix); infix_to_postfix(infix,postfix); printf("\npostfix exp= %s",postfix); } void infix_to_postfix(char infix[],char postfix[]) { char s[20],symbol; int top=-1,i=0,j=0; while(infix[i]!='\0') { symbol=infix[i]; switch(symbol) { case '(':++top;          s[top]=symbol;          break;     case ')':while(s[top]!='(')              {               postfix[j++]=s[top];               top--; }           top--;           break;     case '+':     case '-':     case '*':     case '^':     case '/':           while(precedence(symbol)<=precedence(s[top]) && top!=-1)                    postfix[j++]=s[top--];