Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is the "classic" solution to the FizzBuzz problem.
- for (int i = 1; i <= 100; i++)
- {
- if (i % 3 == 0 && i % 5 == 0)
- {
- Console.WriteLine("FizzBuzz");
- }
- else if (i % 3 == 0)
- {
- Console.WriteLine("Fizz");
- }
- else if (i % 5 == 0)
- {
- Console.WriteLine("Buzz");
- }
- else
- {
- Console.WriteLine(i.ToString());
- }
- }
- // This is a "contemporary" solution to the FizzBuzz problem using ONE LINE of LINQ!
- Enumerable.Range(1, 100).ToList().ForEach(n => Console.WriteLine((n % 3 == 0) ? (n % 5 == 0) ? "FizzBuzz" : "Fizz" : (n % 5 == 0) ? "Buzz" : n.ToString()));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement