Guest User

Untitled

a guest
Apr 26th, 2012
822
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This is the "classic" solution to the FizzBuzz problem.
  2. for (int i = 1; i <= 100; i++)
  3. {
  4.     if (i % 3 == 0 && i % 5 == 0)
  5.     {
  6.         Console.WriteLine("FizzBuzz");
  7.     }
  8.     else if (i % 3 == 0)
  9.     {
  10.         Console.WriteLine("Fizz");
  11.     }
  12.     else if (i % 5 == 0)
  13.     {
  14.         Console.WriteLine("Buzz");
  15.     }
  16.     else
  17.     {
  18.         Console.WriteLine(i.ToString());
  19.     }
  20. }
  21.  
  22. // This is a "contemporary" solution to the FizzBuzz problem using ONE LINE of LINQ!
  23. Enumerable.Range(1, 100).ToList().ForEach(n => Console.WriteLine((n % 3 == 0) ? (n % 5 == 0) ? "FizzBuzz" : "Fizz" : (n % 5 == 0) ? "Buzz" : n.ToString()));
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×