Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

90% of /prog/ can't write FizzBuzz

Name: The antagonist 2008-04-25 12:38

Prove me wrong

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

Name: Anonymous 2008-04-26 20:05


            for (int i = 0; i < 100; i++)
            {
                if(i % 3 == 0)
                    Console.Write("Fizz");
                if(i % 5 == 0)
                    Console.Write("Buzz");
                else if((i % 5) * (i % 3) != 0)
                    Console.Write(i);
                Console.WriteLine();
            }
            Console.ReadKey();

Not a perfect solution, as numbers that are multiples of 3 and not of 5, gets evaluated twice. Apart from that it prints the desired result.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List