FizzBuzz

From Esolang
Jump to: navigation, search

A FizzBuzz program is essentially a count-up program. It prints the numbers one-by-one. But, that also inquires printing "Fizz" when the number is divisible by 3, and printing "Buzz" when the number is divisible by 5. Also, the program needs to print "FizzBuzz" when the number is divisible by 15 (or both divisible by 3 and 5).

In other words, the program outputs:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
...

Examples

C

#include <stdio.h>
int main(void)
{
    int i;
    for(i=1; i<=100; i++)
    {
        if((i%15)== 0)//improved from "(i%3)&&(i%5)"
            printf("FizzBuzz\n");
        else if((i%3)==0)
            printf("Fizz\n");
        else if((i%5)==0)
            printf("Buzz\n");
        else
            printf("%d\n",i);
    }
    return 0;
}

Python 3

for i in range(1,101):
	if i%3==0:
		print("Fizz",end="")
	if i%5==0:
		print("Buzz",end="")
	if i%3 and i%5:
		print(i,end="")
	print()

TeX

\newcount\-\let~\advance\day0\loop~\-1~\day1~\mit\ifnum\-=3\-0Fizz\fi\ifnum\fam=5Buzz\rm\fi\ifvmode\the\day\fi\endgraf\ifnum\day<`d\repeat\bye