- 6th Apr 2023
- 08:59 am
- Admin
C# Homework Help
C# Homework Question
C# Logical Puzzles, Games, and Algorithms: Game of Craps
C# Homework Solution
Here's an example C# program that implements FizzBuzz:
using System;
class FizzBuzz
{
static void Main()
{
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);
}
}
}
}
This program uses a for loop to iterate from 1 to 100, and uses if/else statements to determine whether to print "Fizz", "Buzz", "FizzBuzz", or the number itself. The % operator is used to check if a number is divisible by 3, 5, or both.