Advertisement
nezvers

fizzbuzz_c++

Sep 22nd, 2020
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. string out(int i){
  6.     if (i == 0){
  7.         return to_string(i);
  8.     }
  9.     string output = "";
  10.     if ((i % 3) == 0){
  11.         output += "fizz";
  12.     }
  13.     if ((i % 5) == 0){
  14.         output += "buzz";
  15.     }
  16.     if (output == ""){
  17.         return to_string(i);
  18.     }
  19.     else{
  20.         return output;
  21.     }
  22. }
  23.  
  24. int main()
  25. {
  26.     for(int i= -30; i<100; i++){
  27.         cout << out(i) << endl;
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement