[填空题] 本程序的功能是:找出所有满足各位数字之和正好是其所有质因子之和的三位数。例如378,其各位数字之和为18,而其质因子2,3,3,3,7之和也是18,所以378是满足条件的数。Option

11 查阅

[填空题] 本程序的功能是:找出所有满足各位数字之和正好是其所有质因子之和的三位数。例如378,其各位数字之和为18,而其质因子2,3,3,3,7之和也是18,所以378是满足条件的数。Option ExplicitPrivate Sub CmdFind_Click()Dim i As Integer,p As String,st As String,st1 As StringFor i=100 To 999()If csum(i)=zyz(i,st) Thenp=CStr(i)st1=Left(p,1) & "+" & Mid(p,2,1) & "+" & Right(p,1)List1.AddItem i & ": " & st1 & "=" & Left(st,Len(st)-1)End IfNext iIf List1.ListCount=0 ThenList1.AddItem "无满足要求的数!"End IfEnd SubPrivate Function csum(m As Integer)As Integer ’求各位数字之和Dim i As Integer,p As Stringp=CStr(m)For i=1 To Len(p)()Next iEnd FunctionPrivate Function zyz(ByVal m As Integer,st As String)As Integer ’求所有质因子之和Dim i As Integeri=2DoIf m Mod i=0 Thenzyz=zyz+ist=st & i & "+"m=miEIse()End IfLoop Until ()End Function

参考答案:

st="";csum=csum+val(mid(p,i,A));i=i+A;m=A

计算机考试