m的n次方C語言編程 VB編寫程序,用來計算m的n次方?
VB編寫程序,用來計算m的n次方?新建項目,添加command1控件。VB6.0 XP調(diào)試成功代碼如下:dim n as Integerprivate sub command1_uu2;Click()
VB編寫程序,用來計算m的n次方?
新建項目,添加command1控件。VB6.0 XP調(diào)試成功
代碼如下:
dim n as Integer
private sub command1_uu2;Click()
m=InputBox(“please input base m”)
n=InputBox(“please input index n”)
print JS(m,n)
end sub
private function JS(a as double,B as Integer)
JS a^B
end function
~]//二進制指數(shù)運算,時間復(fù)雜度O(logn),比暴力乘法快得多#include intpoint(INTM,INTN){introt=1 while(n){if(n&0x1)RET=RET*m m,m=m*n>>=1}returnret}voidmain(){printf(%dn”,Pow(2,8))}