急求!vb程式設計題目

時間 2021-05-02 11:23:21

1樓:匿名使用者

dim m as integer, n as integerprivate sub command1_click()m = val(inputbox("輸入正整數"))n = val(inputbox("輸入正整數"))if n * m = 0 then

msgbox "兩數任何乙個數都不能為0!"

exit sub

end if

end sub

private sub command2_click()dim r as integer, s as integerr = m: s = 1

do until m mod r = 0 and n mod r = 0 '最大公約數,選擇任意乙個數,每次減1,知道兩個數除以它都沒有餘數,那麼它肯定就是最大公約數

r = r - 1

loop

do until s mod m = 0 and s mod n = 0 '最小公倍數,s從1開始,慢慢變大,直到除以m,n都沒有餘數,那麼它肯定就是最小公倍數

s = s + 1

loop

text1.text = "最大公約數是:" & r & "最小公倍數是:" & s

end sub

2樓:匿名使用者

我也試著編了乙個,可以參考一下。

dim 小數值 as integer

dim 大數值 as integer

dim 最大公約數 as integer

dim 最小公倍數 as integer

private sub command1_click()

on error resume next

text3.text = ""

text4.text = ""

if val(trim(text1.text)) <= 0 then exit sub

if val(trim(text2.text)) <= 0 then exit sub

if val(trim(text1.text)) >= val(trim(text2.text)) then

大數值 = val(trim(text1.text))

小數值 = val(trim(text2.text))

else

大數值 = val(trim(text2.text))

小數值 = val(trim(text1.text))

end if

最小公倍數 = 1

最大公約數 = 小數值 + 1

1  最大公約數 = 最大公約數 - 1

if 大數值 mod 最大公約數 = 0 and 小數值 mod 最大公約數 = 0 then

text3.text = 最大公約數

goto 2

end if

if 最大公約數 > 1 then goto 1

2  最小公倍數 = 最小公倍數 + 1

if 最小公倍數 mod 大數值 = 0 and 最小公倍數 mod 小數值 = 0 then

text4.text = 最小公倍數

goto 3

end if

if 最小公倍數 < 小數值 * 大數值 then goto 2

3end sub

private sub form_load()

on error resume next

text1.text = ""

text2.text = ""

text3.text = ""

text4.text = ""

end sub

3樓:匿名使用者

以前我是學校的vb助教,只可惜現在手邊沒有vb的書,忘記了。這個應該是比較簡單的題目,你去請教一下你的輔導老師吧。

求1道小學VB程式設計題目謝謝,急求!一道VB程式設計題 謝謝!

private sub form click dim i j s i 1,j 0 do while s 2000 j i j s s j i i 1 loop print n i print s s end sub 有點不記得了 大概是這樣的 你自己除錯一下哈!private sub form cl...

求一道VB題目急求

按照你的意思,相當於把陣列按正序和反序分別輸出。編寫程式如下 dim a 1 to 20 as integer,i as integer for i 1 to 20 a i inputbox 請輸入第 str i 個數 next i for i 1 to 20 print a i next i pr...

VB程式設計高手進, 急 VB程式設計高手進

很簡單的 只告訴你方法思路,現在沒有vb環境所以沒法寫你在text1的keypress時間裡,寫上校驗方法,利用acciss碼來判斷,數字的acciss碼是連續的,你可以查到,除此之外的acciss碼你都不予接受,這樣使用者就無法輸入除了0 9之外的任何內容,如何輸入了,你還可以彈出提示框。思路就這...