mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-27 08:26:20 +00:00
40 lines
619 B
Markdown
40 lines
619 B
Markdown
|
# 6-2 递归实现指数函数
|
|||
|
|
|||
|
本题要求实现一个计算$$x^n$$($$n\ge 1$$)的函数。
|
|||
|
|
|||
|
### 函数接口定义:
|
|||
|
```c++
|
|||
|
double calc_pow( double x, int n );
|
|||
|
```
|
|||
|
函数`calc_pow`应返回`x`的`n`次幂的值。建议用递归实现。题目保证结果在双精度范围内。
|
|||
|
|
|||
|
### 裁判测试程序样例:
|
|||
|
```c++
|
|||
|
#include <stdio.h>
|
|||
|
|
|||
|
double calc_pow( double x, int n );
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
double x;
|
|||
|
int n;
|
|||
|
|
|||
|
scanf("%lf %d", &x, &n);
|
|||
|
printf("%.0f\n", calc_pow(x, n));
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/* 你的代码将被嵌在这里 */
|
|||
|
```
|
|||
|
|
|||
|
### 输入样例:
|
|||
|
```in
|
|||
|
2 3
|
|||
|
```
|
|||
|
|
|||
|
### 输出样例:
|
|||
|
```out
|
|||
|
8
|
|||
|
```
|