From bf1491b6c886a9c165a78c3ba9a5126679fba820 Mon Sep 17 00:00:00 2001 From: jmeline Date: Sat, 22 Oct 2016 23:13:35 -0600 Subject: [PATCH 1/2] algo(cpp-fizzbuzz): added implementation --- .../Interview_Algorithms/fizzbuzz.cpp | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp diff --git a/src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp b/src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp new file mode 100644 index 00000000..943c946e --- /dev/null +++ b/src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp @@ -0,0 +1,37 @@ +#include + +/* + * 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; + } +} From 12a38add61fe2c985cd0514c308fb05e58afcbe0 Mon Sep 17 00:00:00 2001 From: jmeline Date: Sun, 23 Oct 2016 00:37:14 -0600 Subject: [PATCH 2/2] fix(cpp-fizzbuzz): fixed c++ styling issues --- .../Interview_Algorithms/fizzbuzz.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp b/src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp index 943c946e..61ddbba9 100644 --- a/src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp +++ b/src/algorithm_practice/Interview_Algorithms/fizzbuzz.cpp @@ -2,9 +2,10 @@ /* * 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 "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. @@ -13,25 +14,24 @@ * For numbers which are multiples of both three and five print “FizzBuzz”." * */ -bool isDivisibleByX (int number, int divider) { +bool isDivisibleByX(int number, int divider) { return number % divider == 0; } -int main(int argc, char *argv[]) -{ +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)){ + if (isDivisibleByX(i, 3)) { std::cout << "fizz"; } if (isDivisibleByX(i, 5)) { std::cout << "buzz"; } - std::cout << std::endl; } + return 0; }