Advertisement
Guest User

shad / FizzBuzz.cpp

a guest
Dec 17th, 2010
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. /*
  2. Write a program that prints the numbers from 1 to 100.
  3. But for multiples of three print “Fizz” instead of the number and
  4. for the multiples of five print “Buzz”.
  5. For numbers which are multiples of both three and five print “FizzBuzz”.
  6. */
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     int counter;
  13.     for (counter=1;counter<=100;counter++)
  14.     {
  15.         if (counter%3!= 0 && counter%5 != 0)
  16.         {
  17.             cout << counter << endl;
  18.         }
  19.         else
  20.         {
  21.             if (counter % 3 == 0)
  22.                cout << "Fizz";
  23.             if (counter % 5 == 0)
  24.                cout << "Buzz";
  25.             cout << endl;
  26.         }
  27.     }
  28.     cin.get();
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement