本题要求实现一个计算x
n
(n≥0)的函数。
函数接口定义:
double mypow( double x, int n );函数mypow应返回x的n次幂的值。题目保证结果在双精度范围内。
裁判测试程序样例:
#include <stdio.h>double mypow( double x, int n );int main(){ double x; int n; scanf("%lf %d", &x, &n); printf("%fn", mypow(x, n)); return 0;}/* 你的代码将被嵌在这里 */我的答案:
double mypow( double x, int n ){ double num=1;//注意为double型 for(int i=1;i<=n;i++) { num=x*num;//我开始写的是x*x,发现n=1时不行 } return num;}简单题,就不多说了