Coders Lounge

Would you like to react to this message? Create an account in a few clicks or log in to continue.

For all of your programming needs and wants.


2 posters

    A challenge "FIZZBUZZ"

    ProgrammingLinguist
    ProgrammingLinguist
    Stranger
    Stranger


    Posts : 49
    Join date : 2010-01-06
    Location : LA

    A challenge "FIZZBUZZ" Empty A challenge "FIZZBUZZ"

    Post by ProgrammingLinguist 1/6/2010, 10:08 pm

    This is a general coding exercise. It's very popular amongst programmers and requires basic coding knowledge. Since there isn't a "general coding" category I'm posting it in the C++ category because... i like C++ best Very Happy

    Problem:

    Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
    avatar
    GZ
    Stranger
    Stranger


    Posts : 4
    Join date : 2009-10-28

    A challenge "FIZZBUZZ" Empty Re: A challenge "FIZZBUZZ"

    Post by GZ 2/20/2010, 2:27 pm

    Code:
    #include <iostream>
    int main () {
       for ( char i = 0; i < 100; i++ ) {
       if ( i % 3 == 0 ) {
          cout << "Fizz\n";
       } else if ( i % 5 == 0 ) {
          cout << "Buzz\n";
       } else {
          cout << i << endl;
       }
    }

    return 0;
    }

      Current date/time is 3/29/2024, 3:11 am