打卡第十一天

编写一个求x的n次方的函数

一、

1.新定义函数power,在进行调用/

二、

三、

#include<iostream>
using namespace std;

double power(double x,int n)
{
double q=1.0;
while(n--)
q *=x;
return q;
}
int main()
{
cout<<"4的3次方是"<<power(4,3)<<endl;
return 0;

}

四、

#include<iostream>
using namespace std;

double power(double x,int n)
{
double q=1.0;
while(n--)
q *=x;
return q;
}
int main()
{
cout<<"4的3次方是"<<power(4,3)<<endl;
return 0;

}

posted @ 2023-04-25 12:14  欧吼吼  阅读(18)  评论(0编辑  收藏  举报