递归实现指数函数

https://pintia.cn/problem-sets/12/problems/353

 1 double calc_pow(double x, int n)
 2 {
 3     double ret;
 4 
 5     if (n == 0)
 6     {
 7         ret = 1;
 8     }
 9     else
10     {
11         ret = x * calc_pow(x, n - 1);
12     }
13 
14     return ret;
15 }

 

posted @ 2020-01-25 20:33  jason2018  阅读(529)  评论(0编辑  收藏  举报