Advertisement
Guest User

Untitled

a guest
Apr 26th, 2012
899
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()));
Advertisement
RAW Paste Data Copied
Advertisement