Answer to Question #340184 in C for Yoooo

Question #340184

3. FizzBuzz 2.0

by CodeChum Admin

Remember the game of FizzBuzz from the last time? Well, I thought of some changes in the game, and also with the help of loops as well. Firstly, you'll be asking for a random integer and then loop from 1 until that integer. Then, implement these conditions in the game:

  • print "Fizz" if the number is divisible by 3
  • print "Buzz" if the number is divisible by 5
  • print "FizzBuzz" if the number is divisible by both 3 and 5
  • print the number itself if none of the above conditions are met

Input


1. An integer

Output


The first line will contain a message prompt to input the integer.

The succeeding lines will contain either a string or an integer.



Enter·n:·15
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
1
Expert's answer
2022-05-13T03:26:19-0400
#include <stdio.h>
 
int main()
{
    unsigned int number;
    
    printf("%s", "Enter an integer: ");
    scanf("%u", &number);
    
    for ( unsigned int i = 1; i <= number; ++i)
    {
        if (i % 15 == 0)       
            printf ("%s","FizzBuzz\n");
        else if ((i % 3) == 0)   
            printf("%s","Fizz\n");
        else if ((i % 5) == 0)                      
            printf("%s","Buzz\n");
        else          
            printf("%u\n", i);            
    }
}

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