给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。不得使用库函数。
public double Power(
double thebase,
int exponent)
{
if (exponent>
0)
{
double sum =
1.00000;
for (
int i =
0; i < exponent; i++)
{
sum *= thebase;
}
return sum;
}
else
{
double sum =
1.00000;
for (
int i =
0; i < -exponent; i++)
{
sum *= thebase;
}
return 1.00000/
sum;
}
}
转载请注明原文地址: https://www.6miu.com/read-2321.html