Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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);
}
}
}Advertisements