实验2-4-5 简单实现x的n次方 (10 分)
1. 题目摘自
https://pintia.cn/problem-sets/13/problems/412
2. 题目内容
本题要求实现一个计算x的n次幂(n≥0)的函数。
函数接口定义:
double mypow( double x, int n );
函数 mypow
应返回 x
的 n
次幂的值。题目保证结果在双精度范围内。
输入样例:
0.24 4
输出样例:
0.003318
3. 源码参考
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
double mypow(double x, int n);
int main()
{
double x;
int n;
cin >> x >> n;
cout << fixed << setprecision(6) << mypow(x, n) << endl;
return 0;
}
double mypow(double x, int n)
{
return pow(x, n);
}