Write a C# program to solve FizzBuzz problem

CsharpProgrammingServer Side Programming

The FizzBuzz problem states that −

  • Display "Fizz" instead of the number for each multiple of 3,
  • Display "Buzz", instead of the number for each multiple of 5.
  • Display "FizzBuzz", instead of the number for each multiple of 5 & 3

Let us see how to implement the above using C# −

Example

using System;

class Demo {

   static void Main(String[] args) {
      for(int i=1;i<=100;i++) {

         if((i%3 == 0) && (i%5==0))
         Console.WriteLine("FizzBuzz\n");
         else if(i%3 == 0)
         Console.WriteLine("Fizz\n");
         else if(i%5 == 0)
         Console.WriteLine("Buzz\n");
         else
         Console.WriteLine(i);
      }
   }
}
raja
Published on 14-Aug-2018 13:42:44
Advertisements