Let’s play a game of FizzBuzz! It’s quite the same with your childhood "PopCorn" game, but with a little bit of twist to align it with programming.
Are you ready?
Instructions:
Input
1. An integer
Output
The first line will contain a message prompt to input the integer.
The succeeding lines contain strings.
radio_button_unchecked
Test Case 1
Enter n: 15
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
FizzBuzz
radio_button_unchecked
Test Case 2
Enter n: 20
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
FizzBuzz
Fizz
Buzz
#include <bits/stdc++.h>
using namespace std;
int
main ()
{
int n;
cout << "Enter a Number: ";
cin >> n;
for (int i = 1; i <= n; i++)
{
if ((i % 3 == 0) and (i % 5 == 0))
{
cout << "FizzBuzz" << endl;
}
else if (i % 3 == 0)
{
cout << "Fizz" << endl;
}
else if (i % 5 == 0)
{
cout << "Buzz" << endl;
}
else
{
continue;
}
}
}
Comments
Leave a comment