看板 Visual_Basic 關於我們 聯絡資訊
程式如下 Dim a As Integer = Convert.ToInt32(TextBox1.Text) Dim b As Integer = Convert.ToInt32(TextBox2.Text) Dim c As Integer Label1.Text = "" If a >= b Then For c = b To 1 Step -1 Label1.Text &= "最大公因數 = " & number(a, b, c) & vbCrLf Next ElseIf b >= a Then For c = a To 1 Step -1 Label1.Text &= "最大公因數 = " & number(a, b, c) & vbCrLf Next End If End Sub Function number(ByVal a1 As Integer, ByVal b1 As Integer, ByVal c1 As Integer) As Integer If c1 = 1 Then Return 1 ElseIf (a1 Mod c1) = 0 And (b1 Mod c1) = 0 Then Return c1 Else Return number(a1, b1, c1 - 1) End If End Function 跑出來後 會一直label會一直出現最大~最小的公因數 有什麼方法可以讓他只停在第一個最大的嗎? 這是我同學想的程式 他問我 但我想不出來@@ 又再次麻煩大大一下了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.59.230.172 ※ 編輯: ssaume 來自: 61.59.230.172 (12/15 01:32)
fumizuki:可以加 Exit For 離開迴圈 12/15 07:26