-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathfizz-buzz.cpp
More file actions
32 lines (25 loc) · 799 Bytes
/
fizz-buzz.cpp
File metadata and controls
32 lines (25 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// CPP program to print Fizz Buzz
#include <stdio.h>
int main(void)
{
int 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)
printf ("FizzBuzz\t");
// number divisible by 3? print 'Fizz'
// in place of the number
else if ((i%3) == 0)
printf("Fizz\t");
// number divisible by 5, print 'Buzz'
// in place of the number
else if ((i%5) == 0)
printf("Buzz\t");
else // print the number
printf("%d\t", i);
}
return 0;
}