源程序:
#include < iostream.h >
#include < math.h >
double power(double a, int b)
{
int i;
double result = 1.0;
for(i=0;i< b;i++)
result = result * a;
return result;
}
void main()
{
double r;
int n;
cout<<"r = ";
cin>>r;
cout<<"n = ";
cin>>n;
cout<< r<<"的"<< n<<"次幂是:"<< power(r,n)<< endl;
}
运行结果: