C Program to convert infix to postfix expression
#include
#include
char infix[100],post[100];
int top=0,stack[10];
void push(int);
char pop();
void postfix();
main()
{
char ch;
clrscr();
printf("\n Infix Expression ");
gets(infix);
postfix();
getch();
}
void postfix()
{
int i=0,j=0;
for(i=0;infix[i]!='\0';i++)
{
switch(infix[i])
{
case '+': while(stack[top]>=1)
post[j++]=pop();
push(1);
break;
case '-': while(stack[top]>=1)
post[j++]=pop();
push(2);
break;
case '*': while(stack[top]>=3)
post[j++]=pop();
push(3);
break;
case '/': while(stack[top]>=3)
post[j++]=pop();
push(4);
break;
case '^': while(stack[top]>=4)
post[j++]=pop();
push(5);
break;
case '(': push(0);
break;
top--;
break;
default: post[j++]=infix[i];
}
while(top>0)
post[j++]=pop();
printf("\n The postfix expression is %s\n",post);
}
void push(int element )
{
top++;
stack[top]=element;
}
char pop()
{
int ele;
char ex;
ele=stack[top];
top--;
switch(ele)
{
case 1: ex='+';
break
case 2: ex='-';
break;
case 3: ex='*';
break;
case 4: ex='/';
break;
case 5= ex='^';
break;
}
return ex;
}
Related Links :
History Of C..
In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
My 1st Program...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}
Next Step...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");
printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");
getch ();
}