View Single Post
Old 13-08-2009, 21:29   #11
Damien
Remoaner
Cable Forum Team
 
Damien's Avatar
 
Join Date: Mar 2004
Posts: 32,796
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Re: Programming Challenges?

Quote:
Originally Posted by punky View Post
I did more or less the same. Just one suggestion i'd make regarding your code Damien:

Spoiler: 
I'd use else ifs instead of ifs otherwise you'd get unnecessary repitition.

for (Int32 i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0)
Console.WriteLine(i + " is a multiple of both 3 AND 5!");
else if (i % 3 == 0)
Console.WriteLine(i + " is a multiple of 3");
else if (i % 5 == 0)
Console.WriteLine(i + " is a multiple of 5");

}

i.e you get:

12 is a multiple of 3
15 is a multiple of both 3 AND 5!
18 is a multiple of 3

instead of this:

12 is a multiple of 3
15 is a multiple of both 3 AND 5!
15 is a multiple of 3
15 is a multiple of 5
18 is a multiple of 3
Opps! Miss that. Indeed.

---------- Post added at 21:29 ---------- Previous post was at 21:28 ----------

Quote:
Originally Posted by punky View Post
BTW the absolute classic programming challenge is to generate an array of random numbers and then sort it manually. Once you do it, then you can refine it to make it as efficient as possible.

I guarantee every programming course has that exercise.
Let's do that one next then. An array of 10 random numbers should be fine...

I'll try tomorrow.
Damien is offline   Reply With Quote