|
-
Jul 24th, 2007, 10:29 AM
#1
Thread Starter
PowerPoster
quick code
ok this sounds easy but which is the best way of doing this?
in a for loop (lets say up to 100), for numbers where a multiple of X, print something. for a multiple of Y print something else. For a multiple of X and Y, print something else.
does that make sense? how would you find out (or the best way) if you are in multples?
would that be the mod operator? if so, then would this be right?
for (int counter = 0; counter < 100; counter++)
{
if (counter % X == 0)
{
Console.WriteLine("something 1");
}
else if (counter % Y == 0)
{
Console.WriteLine("something 2");
}
else
{
Console.WriteLine(counter.ToString());
}
}
but what about the last part "if they are multples of X and Y"?
Last edited by Techno; Jul 24th, 2007 at 10:41 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|