#include<iostream>
using namespace std;
int main()
{
int base, exponent;
long result = 1;
cout << "enter base and exponent:" << endl;
cin >> base >> exponent;
if(exponent < 0)
{
cout << "exponent can't be small than 0" << endl;
return -1;
}
if(exponent > 0)
{
//计算底数的指数次方
for (int cnt = 1;cnt <= exponent; ++cnt)
result = result * base;
}
//如果指数为0,直接输出即可
cout << base << " raise to the power of " << exponent << ": " << result << endl;
return 0;
}
计算底数的指数次方
最新推荐文章于 2021-07-27 01:54:22 发布