Program 4
Program 4
Develop a Program in C for converting an Infix Expression to Postfix Expression. Program should
support for both parenthesized and free parenthesized expressions with the operators: +, -, *, /, %
(Remainder), ^ (Power) and alphanumeric operands.
*/
// Header files
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
//Global variables
char stack[SIZE],infix[SIZE];
char symb, x;
int top = -1;
//main function
int main()
{
printf("ASSUMPTION: The Infix Expression contains single letter
variables and single digit constants only.\n");
printf("\nEnter the Infix Expression : ");
scanf("%s",infix);
printf("\n");
push('('); // push '(' onto stack
strcat(infix,")"); // append ')' to infix expression where ")" acts as sentinel
infix_postfix(infix);
return 0;
}
/* Output
ASSUMPTION: The Infix Expression contains single letter variables and single digit constants only.
Postfix Expression :A B ^ c * D - E F / G / / + H +
ASSUMPTION: The Infix Expression contains single letter variables and single digit constants only.
Postfix Expression : A B C * D E F ^ / G * - H * +
ASSUMPTION: The Infix Expression contains single letter variables and single digit constants only.
Enter the Infix expression : (3^2*5)/(3*2-3)+5
Postfix Expression: 3 2 ^ 5 * 3 2 * 3 - / 5 +
ASSUMPTION: The Infix Expression contains single letter variables and single digit constants only.
Postfix Expression :A B + C * D E - - F G + ^
ASSUMPTION: The Infix Expression contains single letter variables and single digit constants only.
Postfix Expression :A B + C * D E - - F G + $
*/