Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

FizzBuzz Recursive Solution

By: JackNova on Apr 27th, 2012  |  syntax: C#  |  size: 0.51 KB  |  views: 200  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. static string FizzBuzz(int n) {
  2.             if (n < 3)
  3.                 return "";
  4.             if (n % 5 + n % 3 == 0)
  5.                 return "FizzBuzz," + FizzBuzz(n - 1);
  6.             if (n % 3 == 0)
  7.                 return "Fizz," + FizzBuzz(n - 1);
  8.             if (n % 5 == 0)
  9.                 return "Buzz," + FizzBuzz(n - 1);
  10.             return n + "," + FizzBuzz(n - 1);
  11.         }
  12.  
  13. foreach (var item in FizzBuzz(100).Split(',').Reverse())
  14.             {
  15.                 Console.WriteLine(item);
  16.             }