作者walume (哇!阿鲁米)
看板Visual_Basic
标题Re: [请益]用递回写x^n和求x y的最大公约数
时间Wed May 18 11:59:13 2005
※ 引述《neplayer (neplayer)》之铭言:
: ※ 引述《fumizuki (小狮)》之铭言:
: : Function Power(Base As Integer, Exponent As Integer)
: : If Exponent = 0 Then
: : Power = 1
: : Else
: : Power = Base * Power(Base, Exponent - 1)
: : End If
: : End Function
: : 这是你的,你没有传回值,结果当然是零啦。
: : 至於公因数嘛,实在没办法...
: : 我学 vb 的时候鲜少见到递回的范例,所以不太会写递回/.\
: : 想了半天想不出个流程来:~~
: 回原po
: gcd的程式应该google一下就一整票吧
: 想一下辗转相除法
: function gcd(a as integer, b as integer)
: if b=0
: gcd=a
: else
: gcd=gcd(b,a mod b)
: end
Public a As Double, b As Double, r As Double
____________________________________________________________
Private Sub Command1_Click()
b = Val(Text1.Text) Mod Val(Text2.Text)
r = Val(Text2.Text)
Call GCD(b, r)
Label4.Caption = r
End Sub
____________________________________________________________
Public Function GCD(Number1 As Integer, Number2 As Integer)
If Number2 = 0 Then
GCD = Number1
Else
GCD = GCD(Number2, (Number1 Mod Number2))
End If
End Function
____________________________________________________________
我已经写出来了
PO出来给大家看看
之前PO的那个老师说不能= ="
好像说要改成这样子
下面是我刚刚弄好的次方递回运算
Public x As Integer, y As Integer
____________________________________________________________
Private Sub Command1_Click()
x = Val(Text1.Text)
y = Val(Text2.Text)
Label4.Caption = Power(x, y)
End Sub
____________________________________________________________
Public Function Power(Base As Integer, Exponent As Integer)
If Exponent = 0 Then
Power = 1
Else
Power = Base * Power(Base, Exponent - 1)
End If
End Function
____________________________________________________________
终於弄完了...
谢谢各位帮忙喔^^
--
FUCKFUCKFUCK FUCK FUCK FUCKFUCK FUCK FUCK
FUCK FUCK FUCK FUCK FUCK FUCK FUCK
FUCK FUCK FUCK FUCK FUCKFUCK
FUCKFUCK FUCK FUCK FUCK FUCK FUCK
FUCK FUCK FUCK FUCK FUCK FUCK FUCK
FUCK FUCKFUCK FUCKFUCK FUCK FUCK
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.128.194.155
1F:→ walume:忘记说..要怎麽传回次方那个funtion的值呢@@"140.128.194.155 05/18
2F:推 fumizuki:函数名称 = 传回值 61.222.155.162 05/18
谢谢罗~我在试试看~^^"
※ 编辑: walume 来自: 140.128.194.155 (05/18 12:26)