Home > Backend Development > C#.Net Tutorial > Write a C# program to solve the FizzBuzz problem

Write a C# program to solve the FizzBuzz problem

WBOY
Release: 2023-08-25 20:01:10
forward
1366 people have browsed it

编写一个 C# 程序来解决 FizzBu​​zz 问题

FizzBuzz The question states -

  • displays "Fizz" instead of the number for each multiple of 3,
  • displays " Buzz" instead of every multiple of 5.
  • Display "FizzBuzz" instead of numbers for each multiple of 5 and 3

Let's 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);
      }
   }
}
Copy after login

The above is the detailed content of Write a C# program to solve the FizzBuzz problem. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template