March 2020
Beginner
354 pages
13h 34m
English
Write a program that prints the numbers 1 to 100. But for multiples of 3, print "Fizz" instead of the number, and for the multiples of 5, print "Buzz". For numbers that are multiples of both 3 and 5, print "FizzBuzz".
Here is pseudocode for one solution to the problem:
for (i in 1 to 100) {
if (i mod 15) {
print("FizzBuzz")
} else if (i mod 5) {
print("Buzz")
} else if (i mod 3) {
print("Fizz")
} else {
print(i)
}
}
The program iterates through the numbers 1 to 100. For each iteration, it first checks whether the number is divisible by 15, and if so, it prints “FizzBuzz”. If not, it checks whether the number is divisible by 5 and, if so, prints “Buzz”. If not, it checks ...