Option Explicit
Private Sub Command1_Click() Dim A As Integer, B As Integer, C As Integer Dim i As Integer
A = Val(Text1.Text) B = Val(Text2.Text) If A < B Then C = A A = B B = C Else C = B End If Do While C >= 1 If A Mod C = 0 And B Mod C = 0 Then Label1.Caption = C Exit Do Else C = C - 1 End If Loop
End Sub
数学里列式求法
Option Explicit
Private Sub Command1_Click() Dim A As Integer, B As Integer, C As Integer Dim i As Integer
A = Val(Text1.Text) B = Val(Text2.Text) i = 2 C = 1 Do While A >= i And B >= i If A Mod i = 0 And B Mod i = 0 Then C = C * i A = A / i B = B / i i = 2 Else i = i + 1 End If Loop Label1.Caption = C
End Sub
不用这样写~~~~
用欧,欧几里德算法,非常简单~~
#include <iostream> using namespace std; int main() { int r = -1,m = 119,n = 544; if (m < n) { int temp = m; m = n,n = temp; } while (r != 0) { r = m % n; if (r == 0) break; else m = n,n = r; } cout << n << endl;
return 0; }
[此贴子已经被作者于2004-05-05 11:14:56编辑过]