solve fizbuzz in csharp

One solution to FizzBuzz problem in C# using a for loop and conditional statements can be as follows:

main.cs
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);
    }
}
311 chars
20 lines

Explanation: We loop through integers from 1 to 100 using a for loop. For each integer, we check if it's a multiple of both 3 and 5 first using the && operator, and if it is, we print "FizzBuzz". If it's not a multiple of both, then we check if it's a multiple of 3 only using the % operator, and if it is, we print "Fizz". Similarly, we check if it's a multiple of 5 only, and if it is, we print "Buzz". If none of the above conditions are true, we simply print the integer itself.

gistlibby LogSnag