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
#include <iostream>
using namespace std;
int main(){
int number;
cout<<"Enter number: ";
cin>>number;
//If the number is only divisible by 3, print "Fizz"
if(number%3==0){
printf("Fizz\n");
}
//If the number is only divisible by 5, print "Buzz"
if(number%5==0){
printf("Buzz\n");
}
//If the number is divisible by both 3 and 5, print "FizzBuzz"
if(number%3==0 && number%5==0){
printf("FizzBuzz\n");
}
cin>>number;
return 0;
}
Comments
Leave a comment