Skip to content

Instantly share code, notes, and snippets.

@rajatkhanduja
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajatkhanduja/10345878 to your computer and use it in GitHub Desktop.
Save rajatkhanduja/10345878 to your computer and use it in GitHub Desktop.
Solution of the famous FizzBuzz problem (http://blog.codinghorror.com/why-cant-programmers-program/) in C++
#include<iostream>
using namespace std;
int main(void)
{
for(int i = 1; i <= 100; ++i)
{
if (i % 3 == 0)
{
cout << "Fizz";
}
if (i % 5 == 0)
{
cout << "Buzz";
}
cout << endl;
// or just :
// cout << (i % 3 == 0 ? "Fizz" : "") << (i % 5 == 0 ? "Buzz" : "") << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment