N is a 4-digit positive integer such that the sum of the four digits of N equals the product of the first two digits of N and also equals the product of the last two digits of N.
Find all N's and prove there are no others.
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
For n = 1000 To 9999
ns$ = LTrim(Str(n))
p1 = Val(Mid(ns$, 1, 1)) * Val(Mid(ns$, 2, 1))
p2 = Val(Mid(ns$, 3, 1)) * Val(Mid(ns$, 4, 1))
If p1 = p2 Then
s = sod(n)
If s = p1 Then
Text1.Text = Text1.Text & n & crlf
End If
End If
Next
End Sub
Function sod(n)
s$ = LTrim(Str(n))
tot = 0
For i = 1 To Len(s$)
tot = tot + Val(Mid(s$, i, 1))
Next
sod = tot
End Function
finds
It checks all four-digit numbers.
|
Posted by Charlie
on 2014-06-05 16:41:56 |