Answer to Question #318700 in C++ for Third one

Question #318700

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

1
Expert's answer
2022-03-26T15:29:45-0400


#include <iostream>
using namespace std;


int main(){
	int number;
	cout<<"Enter number: ";
	cin>>number;


	for(int i=1;i<=number;i++){
		//If the number is only divisible by 3, print "Fizz"
		if(i%3==0){
			cout<<"Fizz\n";
		}
		//If the number is only divisible by 5, print "Buzz"
		if(i%5==0){
			cout<<"Buzz\n";
		}
		//If the number is divisible by both 3 and 5, print "FizzBuzz"
		if(i%3==0 && i%5==0){
			cout<<"FizzBuzz\n";
		}
	}




	cin>>number;
	return 0;
}

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