Answer to Question #282517 in C for sunny

Question #282517

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:

  1. Input a positive integer in one line. This will serve as the ending point of your loop.
  2. Loop from 1 to the ending point (inclusive) and perform the following statements:
  3. If the number is only divisible by 3, print "Fizz"
  4. If the number is only divisible by 5, print "Buzz"
  5. If the number is divisible by both 3 and 5, print "FizzBuzz"
  6. If nothing is true in the previous conditions, skip the number

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

Expected Output

Enter n: 15
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
FizzBuzz

radio_button_unchecked

Test Case 2

Expected Output

Enter n: 20
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
FizzBuzz
Fizz
Buzz






1
Expert's answer
2021-12-24T11:45:45-0500
#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;
	}
	
	
    }


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS