下面的程序是找出两个正整数a和b,使得a<b、a+ b=99、a和b的最大公约数是3的倍数,并统计满足条件数对的个数。 Option Explicit Dim a As Integer, b As Integer, n As Integer, c As I

admin2013-04-11  18

问题 下面的程序是找出两个正整数a和b,使得a<b、a+ b=99、a和b的最大公约数是3的倍数,并统计满足条件数对的个数。
Option Explicit
Dim a As Integer, b As Integer, n As Integer, c As Integer
Private Function Gcd (ByVal a As Integer, Byval b As Integer) As Integer
do
c=a Mod b: a=b=c
Loop【  】
Gcd=a
End Function
Private Sub form_ Click()
n=0
for a= 1 To 49
b=【  】
c= Gcd (a, b)
if c Mod 3= 0 then
【  】
Print a, b, c
End if
Next a
Print n
End Sub

选项

答案until c=0或while c<>0,99-a,n=n+1

解析 由求最大公约数的算法可知,当余数c为零时,a为a和b的最大公约数。因条件给定:“a+ b=99”,所以“b=99-a”。n为累计数。
转载请注明原文地址:https://kaotiyun.com/show/o2Qp777K
0

最新回复(0)