All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Odd and Even 2 (Posted on 2015-08-03)
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.)

 No Solution Yet Submitted by K Sengupta No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution | Comment 3 of 4 |
In the same vein as Ady's comment:

494550 - 123775 = 370775

DefDbl A-Z
Dim crlf\$

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

 Search: Search body:
Forums (0)