# 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 `if`s 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);