VB问题,帮我编写程序

来源:百度知道 编辑:UC知道 时间:2024/05/28 19:39:16
编写程序,求四位数的奇数中,所有各位数字之积(且不为0)是60的倍数的数的和。

帮我编写一下

sub test()
dim i as integer
dim s as long
dim a1,a2,a3,a4 as integer
for i=1001 to 9999 step 2
a1=i\1000
a2=(i\100)%10
a3=(i\10)%100
a4=i%1000
if (a1*a2*a3*a4)%60=0 and (a1*a2*a3*a4<>0) then
s=s+i
end if
next i
msgbox s,vbokonly,"result"
end sub

Private Sub Command1_Click()
Dim b, c As Long
For a = 1111 To 9999 Step 1
b = Val(Mid(Str(a), 1, 1)) * Val(Mid(Str(a), 2, 1)) * Val(Mid(Str(a), 3, 1)) * Val(Mid(Str(a), 4, 1))
If b Mod 60 = 0 And (Mid(Str(a), 2, 1)) * (Mid(Str(a), 3, 1)) <> 0 Then c = c + a
Next a
MsgBox c
End Sub