[ create a new paste ] login | about

Link: http://codepad.org/IBnH3vxN    [ raw code | output | fork ]

uskz - C++, pasted on Sep 30:
#include <iostream>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/comparison/equal.hpp>
#include <boost/preprocessor/arithmetic/mod.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>

#define fizzbuzz(z, x, _) \
    BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_MOD(x, 15), 0), \
        std::cout << "FizzBuzz" << std::endl;, \
        BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_MOD(x, 3), 0), \
            std::cout << "Fizz" << std::endl;, \
            BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_MOD(x, 5), 0), \
                std::cout << "Buzz" << std::endl;, \
                std::cout << x << std::endl; \
            ) \
        ) \
    ) \
/**/

int main()
{
    BOOST_PP_REPEAT_FROM_TO(1, 51, fizzbuzz, ~)
}


Output:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz


Create a new paste based on this one


Comments: