幫忙做道題目,用循環(huán)語(yǔ)句做一個(gè)題目,把3條邊都在50內(nèi)的整數(shù)的所有可以成立的RT三角型的邊長(zhǎng)都表示出來(lái)
熱心網(wǎng)友
窗體需要1個(gè)command控件,不要忘記哦!!!!!private sub command1_click()for a=3 to 30 '列舉所有滿(mǎn)足條件的1到50的數(shù),去掉不可能的數(shù),減少運(yùn)行for b=4 to 50for c=5 to 50if a+bc or ab then goto 1 '判斷能否滿(mǎn)足三角形,并且去掉重復(fù)if c^2=a^2+b^2 then print a; b; c 'RT三角形的條件1next cnext bnext aend sub 或Private Sub command1_click()Dim a As Single, b As Single, c As SingleFor a = 3 To 30'列舉所有滿(mǎn)足條件1到50的數(shù),去掉不可能的數(shù),減少運(yùn)行For b = 4 To 50For c = 5 To 50If a + b c And Abs(a - b) < c And a < b Then '判斷能否滿(mǎn)足三角形,并且去掉重復(fù)If c ^ 2 = a ^ 2 + b ^ 2 Then Print a; b; c 'RT三角形的條件,并且打印出來(lái)End IfNext cNext bNext aEnd Sub希望你的VB越學(xué)越好!學(xué)習(xí)進(jìn)步!!!!!!你可以復(fù)制到VB中就可以了!!!。
熱心網(wǎng)友
這是最簡(jiǎn)單一種版本,但可能速度比較慢.窗體就只需要1個(gè)command控件private sub command1_click()for a=1 to 50 '列舉所有1到50的數(shù)for b=1 to 50for c=1 to 50if a+bc then goto 10 '判斷能否滿(mǎn)足三角形,這樣可以減少運(yùn)算if c*c=a*a+b*b then print a,b,c 'RT三角形的條件next cnext bnext a10end sub
熱心網(wǎng)友
法國(guó)北方
熱心網(wǎng)友
題目沒(méi)看懂