Write a program to solve the classic FizzBuzz problem. The program should output integers 1 thru 100, one to a line.However, if the number is divisible by 3 it should output Fizz instead of the number; if the number is divisible by 5 it should output Buzz instead of the number and if it is divisible by both 3 and 5, it should output Fizz Buzz instead. write in C
Code is:
#include <stdio.h>
int main()
{
int i=0;
//Looping from 1 to 100
for(i=1;i<=100;i++)
{
//checking if number divisible by 5 and 3
if (i%15==0)
{
printf("Fizzbuzz");
}
//checking for number divisible by 5
else if (i%5==0)
{
printf("Buzz");
}
//checking for number divisible by 4
else if (i%3==0)
{
printf("Fizz");
}
//printing the number
else
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.