General discussion

Locked

shd'nt print a line where cnt <> cnt2?

By vkaapai ·
a line where cnt <> cnt2 shldn't print
Private Sub Command1_Click()
i = InputBox("PPP")
cnt = 0
cnt2 = 1

For j = 2 To i
cnt = 0

For k = 2 To j
m = 0
For l = 2 To k
If k Mod l = 0 Then
m = m + 1
End If
Next l
restartline:
If m = 1 Then
cnt = cnt + 1

Print k; "( cnt="; cnt; ")"; "( cnt2="; cnt2; ")";
' Print
End If

Next k
'Print
Print
cnt2 = cnt2 + 1

Next j

End Sub

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Tony Hopkinson In reply to shd'nt print a line where ...

k mod i will equal 0 if k is a multiple of i
ie 3,6,9 mod 3 will always equal 0
Your test is on m tho, so it will print if there is only one exact multiple of i in the range 2 to k for each 2 to j. nothing to do with cnt and cnt2.

I think anyway.

PS some descriptive variable names, a comment or two and a description of what the code is trying to achieve , would be a positive boon.
It's a good habit to get into, if you did something like this at work, you'd be in for a serious chat.

You'd get 0 out of 10 from me even if it worked.

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums