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:
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
#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);
}
}
Comments
Leave a comment