-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathfizzbuzz.cpp
More file actions
37 lines (34 loc) · 997 Bytes
/
fizzbuzz.cpp
File metadata and controls
37 lines (34 loc) · 997 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
33
34
35
36
37
#include <iostream>
/*
* Fizz Buzz
* The "Fizz-Buzz test" is an interview question
* designed to help filter out the 99.5% of programming
* job candidates who can't seem to program their way out
* of a wet paper bag.
*
* The text of the programming assignment is as follows:
* "Write a program that prints the numbers from 1 to 100.
* But for multiples of three print “Fizz” instead of the number
* and for the multiples of five print “Buzz”.
* For numbers which are multiples of both three and five print “FizzBuzz”."
*
*/
bool isDivisibleByX(int number, int divider) {
return number % divider == 0;
}
int main(int argc, char *argv[]) {
int maxRange;
std::cout << "Input a range" << std::endl;
std::cin >> maxRange;
for (int i = 0; i < maxRange; i++) {
std::cout << i << ": ";
if (isDivisibleByX(i, 3)) {
std::cout << "fizz";
}
if (isDivisibleByX(i, 5)) {
std::cout << "buzz";
}
std::cout << std::endl;
}
return 0;
}