Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Linq;
- namespace FizzBuzz
- {
- class Program
- {
- private static void Main()
- {
- FizzBuzz02();
- }
- private static void FizzBuzz02()
- {
- var fizzbuzz = new[]
- {
- new[] {"Fizz", "FizzBuzz"},
- new[] {"Buzz", ""},
- };
- const int n = 100;
- for (var i = 1;i <= n;++i)
- {
- fizzbuzz[1][1] = i.ToString(CultureInfo.InvariantCulture);
- var f = (int) Math.Ceiling((i%3)/(double) n);
- var b = (int) Math.Ceiling((i%5)/(double) n);
- Console.Write(i + ": " + fizzbuzz[f][b] + Environment.NewLine);
- }
- }
- private static void FizzBuzz01(){
- var matchers = new[]
- {
- new Tuple<int, string>(3, "Fizz"),
- new Tuple<int, string>(5, "Buzz")
- };
- for (var i = 1; i <= 100; i++) {
- var matches = matchers.Where(c => i % c.Item1 == 0).ToList();
- if (matches.Any())
- foreach (var comb in matches)
- Console.Write(comb.Item2);
- else
- Console.Write(i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment