方法一:
#include <iostream>
using namespace std;
double power(double x,int n);
int main()
{
double x;
int n;
cout<<"please enter x:";
cin>>x;
cout<<"please enter n:";
cin>>n;
cout<<power(x,n)<<endl;
return 0;
}
double power(double x,int n)
{
double sum=1.0;
while(n--)
{
sum *= x;
}
return sum;
}
结果图: