#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
double readnumber(char f[],int *i){
double x=0.0;
int k=0;
while(f[*i]>='0'&&f[i]<'9'){
x=x*10+(f[*i-'0']);
(*i)++;
}
if(f[*i]=='.'){
(*i)++;
while(f[*i]>='0'&&f[i]<'9'){
x=x*10+(f[*i-'0']);
(*i)++;
k++;
}
}
while(k!=0){
x=x/10.0;
k--;
}
return(x);
}
double evalpost(char f[]){
double obst[100];
int top,i;
double x1,x2;
while(f[i]!='#'){
if(f[i]>='0'&&f[i]<'9'){
obst[top]=readnumber(f,&i);top++;
}
else if(f[i]==' ') i++;
else if(f[i]=='+'){
x2=obst[--top];
x1=obst[--top];
obst[top]=x1+x2;top++;
i++;
}
else if(f[i]=='-'){
x2=obst[--top];
x1=obst[--top];
obst[top]=x1-x2;top++;
i++;
}
else if(f[i]==''){
x2=obst[--top];
x1=obst[--top];
obst[top]=x1x2;top++;
i++;
}
else if(f[i]=='/'){
x2=obst[--top];
x1=obst[--top];
obst[top]=x1/x2;top++;
i++;
}
}
return obst[0];
}
int main(int argc, char *argv[]) {
char a[100];
scanf("%c%c",a);
int m=evalpost(a[100]);
printf("%lf",m);
return 0;
}
代码功能归根结底不是别人帮自己看或讲解或注释出来的;而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。
提醒:再牛×的老师也无法代替学生自己领悟和上厕所!
单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。
别用Dev C++了!换这个:Visual C++ 2010 Express简体中文版 http://pan.baidu.com/s/1bnwRVLt