Last active
September 19, 2022 22:29
-
-
Save ashafq/8fc1cf79c7ac81f7432c2e9467943878 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Public domain | |
*/ | |
#include <iostream> | |
#include <string> | |
void fizzbuzz(int start, int stop) { | |
int i = start; | |
switch (i % 15) { | |
for (; i <= stop; i += 15) { | |
case 0: | |
if (i) { | |
std::cout << "FizzBuzz\n"; | |
} else { | |
std::cout << std::to_string(i) << '\n'; | |
} | |
case 1: | |
std::cout << std::to_string(i + 1) << '\n'; | |
case 2: | |
std::cout << std::to_string(i + 2) << '\n'; | |
case 3: | |
std::cout << "Fizz\n"; | |
case 4: | |
std::cout << std::to_string(i + 4) << '\n'; | |
case 5: | |
std::cout << "Buzz\n"; | |
case 6: | |
std::cout << "Fizz\n"; | |
case 7: | |
std::cout << std::to_string(i + 7) << '\n'; | |
case 8: | |
std::cout << std::to_string(i + 8) << '\n'; | |
case 9: | |
std::cout << "Fizz\n"; | |
case 10: | |
std::cout << "Buzz\n"; | |
case 11: | |
std::cout << std::to_string(i + 11) << '\n'; | |
case 12: | |
std::cout << "Fizz\n"; | |
case 13: | |
std::cout << std::to_string(i + 13) << '\n'; | |
case 14: | |
std::cout << std::to_string(i + 14) << '\n'; | |
} | |
} | |
} | |
int main() { | |
fizzbuzz(0, 100); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment