VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   600
      TabIndex        =   0
      Top             =   2640
      Width           =   1335
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Base 1
Private Function gcd(ByVal m%, ByVal n%) As Integer
   If m < n Then t = m: m = n: n = t
    Do
     r = m Mod n
     If r = 0 Then Exit Do
     m = n
     n = r
   Loop
   gcd = n
End Function


Private Sub Command1_Click()
  Dim a() As Integer
  n = InputBox("输入n")
  ReDim a(n)
  For i = 1 To n                 '输入要求公约数的n个数
   a(i) = InputBox("输入数据")
  Next i
  n1 = a(1)
  For i = 2 To n                'n个数调用n-1次gcd函数过程求最大公约数
    m1 = a(i)
    mn = gcd(m1, n1)
    If mn = 1 Then Exit For Else n1 = mn    '只要某次求得的最大公约数为1,不再往下求
  Next i
  Print mn                      '显示n个数中的最大公约数
End Sub
