Skip to content

Commit

Permalink
algo(cpp-fizzbuzz): added implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeline committed Oct 23, 2016
1 parent 95e52a4 commit bf1491b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
}

0 comments on commit bf1491b

Please sign in to comment.