Answer to Question #283744 in C++ for Collay

Question #283744

1. FizzBuzz

by CodeChum Admin


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 a random positive integer in one line. This will serve as the ending point of your loop.

Using a for() loop, loop from 1 to the ending point (inclusive) and perform the following statements:

If the number is only divisible by 3, print "Fizz"

If the number is only divisible by 5, print "Buzz"

If the number is divisible by both 3 and 5, print "FizzBuzz"

If nothing is true in the previous conditions, skip the number

Input


A line containing an integer.


15

Output


Multiple lines containing a string.


Fizz

Buzz

Fizz

Fizz

Buzz

Fizz

FizzBuzz


1
Expert's answer
2021-12-31T08:59:49-0500
#include <iostream> 

using namespace std;

int main()
{
	int number;
	cout<<"Input a random positive integer in one line: ";
	cin>>number;
	cout<<"Multiple lines containing a string:\n";
	for(int i=1;i<=number;i++)
	{
		if((i%3==0)&&(i%5==0))
		{
			cout<<"FizzBuZZ\n";
		}
		else if(i%3==0)
		{
			cout<<"Fizz\n";
		}
		else if(i%5==0)
		{
			cout<<"Buzz\n";		}
	}
}

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