``//逆波兰表达式
//一个数即是一个逆波兰表达式
//运算符 逆波兰表达式 逆波兰表达式
//定义即看出来是递归 循环定义递归定义
//递归终止条件,w问题形式本身就是递归
#include<stdio.h>
#include<stdlib.h> 在这里插入代码片
double exp();
int main()
{
printf("%lf",exp());
return 0;
}
double exp()
{
char s[20];
scanf("%c\n",&s);
switch(s[0]){
case '+':return exp()+exp();
case '-':return exp()-exp();
case '*':return exp()*exp();
case '/':return exp()/exp();
default :return atof(s);//读入的就是一个数
break;//atof用法是把字符型转换成浮点型
}
}
08-05
975
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)