Fizz Buzz

The C programming language is everywhere, and learning it will help you become a better programmer ready for the next challenge in any field of computer science!
Hi, I am doing a project built in the Fizz Buzz, and this is the link to describe https://www.codecademy.com/courses/learn-c/projects/fizzbuzz-c.
This is my code, my out put is not correct.

Might be good to double check the instructions.

First your formatting, the want you to output Fizz instead of the number if it’s divisible by 3, not both.

Second, you also need to add conditions checking if the number is divisible by 5, and if the number is divisible by both 3 and 5.

1 Like

Hi,
I am jumping in to ask for help because I have a similar problem. I am not sure how to get the programme to replace the relevant numbers with Fizz, Buzz and Fizzbuzz. I thought an else statement would mean that only the numbers would be printed if the above conditions are not true, but it didn’t seem to work. Could anyone offer some advice?

1 Like

Hi,
I had the same problem. I’ve put if statement for printing “FizzBuzz” on top, before “Fizz” and “Buzz” and it worked.

maybe some of the ifs should be else if

Hi, I was wondering why || is correct rather than && for this fizz buzz problem?

#include <stdio.h>

int main(void)
{
int i;
for(i=1; i<=100; i++)
{
if(((i%3)||(i%5))== 0)
printf(“number= %d FizzBuzz\n”, i);
else if((i%3)==0)
printf(“number= %d Fizz\n”, i);
else if((i%5)==0)
printf(“number= %d Buzz\n”, i);
else
printf(“number= %d\n”,i);

}

return 0;

}

&& is correct if you do it this way

if (((i%3) == 0) && ((i%5)== 0))

My solution for FizzBuzz in C
kept in simple and per the learning thus far
#include <stdio.h>

int main() {
for (int i = 1; i <= 100; i++) {

if (i % 15 == 0) {
  printf("FizzBuzz\n");
} 
else if (i % 3 == 0) {
  printf("Fizz\n");
}
else if (i % 5 == 0) {
  printf("Buzz\n");
}
else {
  printf("%d\n", i);
}

}
printf(“Pretty cool”);
}

This is what I did:

for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
printf(“Fizzbuzz\n”);
continue;
}
if (i % 3 == 0) {
printf(“Fizz\n”);
}
if (i % 5 == 0) {
printf(“Buzz\n”);
}
else {printf(“%d\n”, i);
}
}

Somewhat different, but this worked for me:

#include <stdio.h>

int main() {

int i = 0;
int counter;
i++;

for (i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
printf(“FizzBuzz\n”);
} else if (i % 5 == 0) {
printf(“Buzz\n”);
} else if (i % 3 == 0) {
printf(“Fizz\n”);
} else {
printf(“%d\n”, i);
}

}
return 0;
}

That is the solution.

for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
printf(“FizzBuzz\n”);
} else if (i % 3 == 0) {
printf(“Fizz\n”);
} else if (i % 5 == 0) {
printf(“Buzz\n”);
} else {
printf(“%d\n”, i);

As far as I know, FizzBuzz is composed of two words: one Fizz and another Buzz. Fizz is used in place for numbers divisible by 3 and Buzz is used numbers divisible by 5. What you did wrong mainly is that you did program the part for Fizz but you did not program the part for Buzz. Try coding the part for Buzz (similiar to Fizz but use 5 instead of 3) then see if it works as exepected.

Also see this link to know more about Fizz Buzz.