數值的整數次方

2021-07-31 09:20:18 字數 757 閱讀 9979

給定乙個double型別的浮點數base和int型別的整數exponent。求base的exponent次方。

考慮的幾種情況:

1. base和0的大小

2.exponent是否為負數

class solution   

//計算正指數的整數次方

double powerwithunsignedexponent(double base,unsigned int exponent)

//利用乘方性質計算整數次方

double powerwithunsignedexponent2(double base,unsigned int exponent)

bool g_invalidinput=false;//使用全域性變數處理錯誤

double power(double base, int exponent)

unsigned int ab***ponent=(unsigned int) (exponent);

if(exponent<0)

ab***ponent=(unsigned int) (-exponent);

double result=powerwithunsignedexponent2(base,ab***ponent);

if(exponent<0)

result=1.0/result;

return result;

}};

數值整數次方

題目 實現函式double power double base,int exponent 求base的exponent次方。不得使用庫函式,同時不需要考慮 大數問題。includebool equal double num1,double num2 double powerwithunsignede...

數值整數次方

題目 實現函式double power double base,int exponent 求base的exponent次方。不得使用庫函式,同時不需要考慮 大數問題。includebool equal double num1,double num2 double powerwithunsignede...

數值的整數次方

題目 實現函式double power double base,int exponent 求base的exponent次方。不得使用庫函式,同時不需要考慮大樹問題。這道題目有以下幾點需要注意 0的0次方是無意義的,非法輸入 0的負數次方相當於0作為除數,也是無意義的,非法輸入 base如果非0,如果...