سلام من این برنامه رو از همین سایت گرفتم برای محاسبه عبارت عددی هست چرا جواب نمی ده کسی میدونه مشکل چیه
#include<stdio.h>
#include
<conio.h>
#define m 21
struct stack{
int mytop;
float items[m];
}
void push(stack *s,char);
void pop(stack *s,char *);
void push(stack *s,float);
void pop(stack *s,float *);
int empty(stack *s);
void popAndtest(stack *s,char *x,int *underflow);
void topAndtest(stack *s,char *x,int *underflow);
int isOperand(char);
void convert(char[],char[]);
int pred(char,char);
int isDigit(char);
float evaluate(char []);
float operate(char,float,float);
int main()
{
char infix[m],postfix[m];
int i;
clrscr();
printf("enter an infix expression:");
gets(infix);
convert(infix,postfix);
printf("Evaluation of expression is:%.2f",evaluate(postfix));
printf("postfix expression is:");
for(i=0;postfix[i];i++)
printf("%c",postfix[i]);
getch();
return 0;
}
//*****************************
void convert(char infix[],char postfix[])
{
char symbol,topsymbol;
int underflow,i,j=0;
stack s;
s.mytop=-1;
for(i=0;infix[i],i++)
{
symbol = infix[i];
if(isOperand(symbol))
postfix[j++] = symbol;
elseif(symbol == '(')
push(&s,symbol);
elseif(symbol == ')')
{
pop(&s,&topsymbol);
while(topsymbol != '(')
{
postfix[j++] = topsymbol;
pop(&s,&topsymbol);
}
//end of while
}
//end of else if
else
{
topAndtest(&s, &topsymbol, &underflow);
//if op1 >op2 then true
if(empty(&s)||(!pred(topsymbol,symbol)))
push(&s,symbol);
else
{
popAndtest(&s,&topsymbol,&underflow);
while(pred(topsymbol,symbol) && !underflow)
{
postfix[j++] == topsymbol;
popAndtest(&s,&topsymbol,&underflow);
}
push(&s,symbol);
}
//end of else
}
//end of else
}
//end of for
while(!empty(&s))_
{
pop(&s,&topsymbol);
postfix[j++]==topsymbol;
}
postfix[j] ='\o';
}
//************************************
int isOperand(char symbol)
{
if(symbol >='0' && symbol <= '9')
return 1;
return 0;
}
//************************************
void push(stack *s,char x)
{
s -> items[++(s -> mytop)]=x;
}
//************************************
void pop(stack *s,char *x)
{
*x=s ->items[(s -> mytop)--];
}
//************************************
void popAndtest(stack *s,char *x,int *underflow)
{
if(empty(s))
*underflow=1;
else
{
*x= s -> items[(s -> mytop)--];
*underflow=0;
}
}
//*************************************
void topAndtest(stack *s,char *x,int *underflow)
{
if(empty(S))
*underflow=1;
else
{
*x=s -> items[s ->mytop];
*underflow=0;
}
}
//**************************************
int empty(stack *s)
{
if(s -> mytop == -1)
return 1;
else
return 0;
}
//**************************************
int pred(char op1,char op2)
{
int i,p1,p2;
/* ( + - * / % */
staticchar op[] = {'(','+','-','*','/','%','\0'};
staticint isp[] = {0,12,12,13,13,13};
for(i=0;op[i];i++)
if(op[i]==op1)
{
p1=i;
break;
}
for(i=0;op[i];i++)
if(op[i]==op2)
{
p=i;
break;
}
if(isp[p1]> = isp[p2])
return 1;
return 0;
}
//********************************
float evaluate(char postfix[])
{
float value,operand1,operand2;
char symbol;
stack s;
s.mytop = -1;
int i;
for(i=0;postfix[i];i++)
{
symbol=postfix[i];
if(isdigit(symbol))
push(&s,(float)(symbol - '0'));
else
{
pop(&s,&operand2);
pop(&s,&operand1);
value=operate(symbol,operand1,operand2);
push(&s,value);
}
//end of else
}
//end of for
pop(&s,&value);
return value;
}
//***********************************
int isdigit(char symbol)
{
return (symbol >= '0' && symbol <= '9');
}
//***********************************
float operate(char symbol, float operand1,float operand2)
{
switch(symbol)
{
case'+':
return operand1 + operand2;
case'-':
return operand1 - operand2;
case'*':
return operand1 * operand2;
case'/':
return operand1 / operand2;
case'%':
return operand1 % operand2;
}
}
//*************************************
void push(stack *s,float x)
{
s -> items[++(s -> mytop)]=x;
}
//*************************************
void pop(stack *s,float *x)
{
*x= s -> items[(s -> mytop)--];
}