递归练习:逆波兰表达式求解

题目链接:http://ica.openjudge.cn/dg1/2/

http://noi.openjudge.cn/ch0202/1696/

逆波兰表达式的递归定义:
1) 一个数是一个逆波兰表达式,值为该数。
2) "运算符 逆波兰表达式 逆波兰表达式" 是逆波兰表达式 值为两个逆波兰表达式的值运算的结果 。

 1 #include <stdio.h>
 2 #include<stdlib.h>
 3 double exp()
 4 {
 5     char a[10];
 6     scanf("%s", a);
 7     switch(a[0])
 8     {
 9         case'+': return exp( ) + exp( );
10         case'-': return exp( ) - exp( );
11         case'*': return exp( ) * exp( );
12         case'/': return exp( ) / exp( );
13         default: return atof(a);
14     }
15 }
16 int  main()
17 {
18     double ans;
19     ans = exp();
20     printf("%lf", ans);
21     return 0;
22 }

原文地址:https://www.cnblogs.com/huashanqingzhu/p/3594194.html