Fizz Buzz is a very simple programming task, asked in software developer job interviews.
A typical round of Fizz Buzz can be:
Write a program that prints the numbers from 1 to 100 and for multiples of ‘3’ print “Fizz” instead of the number and for the multiples of ‘5’ print “Buzz”.
// CPP program to print Fizz Buzz
#include<stdio.h>intmain(void){inti;for(i=1;i<=100;i++){// number divisible by 3 and 5 will
// always be divisible by 15, print
// 'FizzBuzz' in place of the number
if(i%15==0)printf("FizzBuzz\t");// number divisible by 3? print 'Fizz'
// in place of the number
elseif((i%3)==0)printf("Fizz\t");// number divisible by 5, print 'Buzz'
// in place of the number
elseif((i%5)==0)printf("Buzz\t");else// print the number
printf("%d\t",i);}return0;}
// Java program to print Fizz Buzz
importjava.util.*;classFizzBuzz{publicstaticvoidmain(Stringargs[]){intn=100;// loop for 100 times
for(inti=1;i<=n;i++){if(i%15==0)System.out.print("FizzBuzz"+" ");// number divisible by 5, print 'Buzz'
// in place of the number
elseif(i%5==0)System.out.print("Buzz"+" ");// number divisible by 3, print 'Fizz'
// in place of the number
elseif(i%3==0)System.out.print("Fizz"+" ");// number divisible by 15(divisible by
// both 3 & 5), print 'FizzBuzz' in
// place of the number
else// print the numbers
System.out.print(i+" ");}}}
// C# program to print Fizz Buzz
usingSystem;classGFG{// Driver Code
publicstaticvoidMain(){intn=100;// loop for 100 times
for(inti=1;i<=n;i++){// number divisible by 5,
// print 'Buzz' in place
// of the number
if(i%15==0)Console.Write("FizzBuzz"+" ");// number divisible by 3,
// print 'Fizz' in place
// of the number
elseif(i%3==0)Console.Write("Fizz"+" ");// number divisible by
// 15(divisible by both
// 3 & 5), print 'FizzBuzz'
// in place of the number
elseif(i%5==0)Console.Write("Buzz"+" ");// print the numbers
elseConsole.Write(i+" ");}}}
#Python program to print Fizz Buzz#loop for 100 times i.e. rangeforfizzbuzzinrange(100):# number divisible by 3, print 'Fizz' # in place of the numberiffizzbuzz%15==0:print("FizzBuzz")continue# number divisible by 5, print 'Buzz'# in place of the numbereliffizzbuzz%3==0:print("Fizz")continue# number divisible by 15 (divisible # by both 3 & 5), print 'FizzBuzz' in# place of the numbereliffizzbuzz%5==0:print("Buzz")continue# print numbersprint(fizzbuzz)
<?php// PHP program to print Fizz Buzz
$i;for($i=1;$i<=100;$i++){// number divisible by 3 and
// 5 will always be divisible
// by 15, print 'FizzBuzz' in
// place of the number
if($i%15==0)echo"FizzBuzz"." ";// number divisible by 3? print
// 'Fizz' in place of the number
elseif(($i%3)==0)echo"Fizz"." ";// number divisible by 5, print
// 'Buzz' in place of the number
elseif(($i%5)==0)echo"Buzz"." ";else// print the number
echo$i," ";}?>