File tree 1 file changed +37
-0
lines changed
src/algorithm_practice/Interview_Algorithms
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ /*
4
+ * Fizz Buzz
5
+ * The "Fizz-Buzz test" is an interview question designed to help filter out the
6
+ * 99.5% of programming job candidates who can't seem to program their way out of
7
+ * a wet paper bag.
8
+ *
9
+ * The text of the programming assignment is as follows:
10
+ * "Write a program that prints the numbers from 1 to 100.
11
+ * But for multiples of three print “Fizz” instead of the number
12
+ * and for the multiples of five print “Buzz”.
13
+ * For numbers which are multiples of both three and five print “FizzBuzz”."
14
+ *
15
+ */
16
+ bool isDivisibleByX (int number, int divider) {
17
+ return number % divider == 0 ;
18
+ }
19
+
20
+ int main (int argc, char *argv[])
21
+ {
22
+ int maxRange;
23
+ std::cout << " Input a range" << std::endl;
24
+ std::cin >> maxRange;
25
+
26
+ for (int i = 0 ; i < maxRange; i++) {
27
+ std::cout << i << " : " ;
28
+ if (isDivisibleByX (i, 3 )){
29
+ std::cout << " fizz" ;
30
+ }
31
+ if (isDivisibleByX (i, 5 )) {
32
+ std::cout << " buzz" ;
33
+ }
34
+
35
+ std::cout << std::endl;
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments