Write a C# program to solve FizzBuzz problem


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
");          else if(i%3 == 0)          Console.WriteLine("Fizz
");          else if(i%5 == 0)          Console.WriteLine("Buzz
");          else          Console.WriteLine(i);       }    } }

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 21-Jun-2020

207 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements