#include<iostream>
using namespace std;
int getpower(int x,int y);
double getpower(double x,int y);
int main()
{
int inumber,power;
double dnumber;
int ianswer;
double danswer;
cout<<"enter an int base number:";
cin>>inumber;
cout<<"enter a double base number:";
cin>>dnumber;
cout<<" to what power?";
cin>>power;
ianswer=getpower(inumber,power);
danswer=getpower(dnumber,power);
cout<<inumber<<"to the"<<power<<"the power is"<<ianswer<<endl;
cout<<dnumber<<"to the"<<power<<"the power is"<<danswer<<endl;
return 0;
}
int getpower(int x,int y)
{
if(y=1)
return x;
else if(y=0)
return 1;
else if(y<0)
return 0;
else
return (x*getpower(x,y-1));
}
double getpower(double x,int y)
{
if(y=1)
return x;
else if(y=0)
return 1;
else if(y<0)
return 1/getpower(x,-y);\
else
return(x*getpower(x,y-1));
}
结果
如:
enter an int base number:67
enter a double base number:90
to what power?45
67to the45the power is67
90to the45the power is90
--------------------------------
Process exited after 17.58 seconds with return value 0
请按任意键继续. . .