#include<stdio.h>
#include<conio.h>
void main()
{
char q[30],s[30],p[30];
int i,top=0,a=0;
clrscr();
printf("\n enter your expretion :");
scanf("%s",q);
strcat(strrev(q),"(");
s[top]=')';
for(i=0;q[i];i++)
{
switch(q[i])
{
case ')':
top++;
s[top]=q[i];
break;
case '+':
case '-':
while(s[top]=='*'||s[top]=='/')
{
p[a]=s[top];
top--;
a++;
}
top++;
s[top]=q[i];
break;
case '*':
case '/':
while(s[top]=='^')
{
p[a]=s[top];
top--;
a++;
}
top++;
s[top]=q[i];
break;
case '^':
top++;
s[top]=q[i];
break;
case '(':
while(s[top]!=')')
{
p[a]=s[top];
top--;
a++;
}
break;
default:
p[a]=q[i];
a++;
}
}
for(i=a-1;i>=0;i--)
printf("%c",p[i]);
getch();
}
#include<conio.h>
void main()
{
char q[30],s[30],p[30];
int i,top=0,a=0;
clrscr();
printf("\n enter your expretion :");
scanf("%s",q);
strcat(strrev(q),"(");
s[top]=')';
for(i=0;q[i];i++)
{
switch(q[i])
{
case ')':
top++;
s[top]=q[i];
break;
case '+':
case '-':
while(s[top]=='*'||s[top]=='/')
{
p[a]=s[top];
top--;
a++;
}
top++;
s[top]=q[i];
break;
case '*':
case '/':
while(s[top]=='^')
{
p[a]=s[top];
top--;
a++;
}
top++;
s[top]=q[i];
break;
case '^':
top++;
s[top]=q[i];
break;
case '(':
while(s[top]!=')')
{
p[a]=s[top];
top--;
a++;
}
break;
default:
p[a]=q[i];
a++;
}
}
for(i=a-1;i>=0;i--)
printf("%c",p[i]);
getch();
}
No comments:
Post a Comment