One solution to FizzBuzz problem in C# using a for loop and conditional statements can be as follows:
main.cs311 chars20 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