Determine the sum of all 3-digit positive integers which contain at least one odd digit and at least one even digit. (For purposes of the problem, zero is an even digit.)
In the same vein as Ady's comment:
494550 - 123775 = 370775
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For n = 100 To 999
s$ = LTrim(Str(n))
odd = 0: even = 0
For i = 1 To 3
If InStr("02468", Mid(s, i, 1)) > 0 Then even = 1
If InStr("13579", Mid(s, i, 1)) > 0 Then odd = 1
Next
If odd * even Then
tot = tot + n
Else
totn = totn + n
Text1.Text = Text1.Text & Str(n)
DoEvents
End If
tottot = tottot + n
Next n
Text1.Text = Text1.Text & crlf & Str(tottot) & Str(totn) & Str(tot) & " done"
End Sub
|
Posted by Charlie
on 2015-08-03 10:15:05 |