codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
/*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”. */ #include <stdio.h> #include <stdarg.h> #include <stdbool.h> int main(int argc, char* argv[]) { int i; for (i = 1; i <= 100; i++) { #if 0 int val = 0; if ((i % 3) == 0) val |= 1; // fizz if ((i % 5) == 0) val |= 2; // buzz switch( val ) { default: printf( "%d\n", i ); break; case 1: printf( "Fizz\n" ); break; case 2: printf( "Buzz\n" ); break; case 3: printf( "FizzBuzz\n" ); break; } #else bool fizz = (i % 3) == 0; // fizz bool buzz = (i % 5) == 0; // buzz if (fizz && buzz) { printf( "FizzBuzz\n" ); } else if (fizz) { printf( "Fizz\n" ); } else if (buzz) { printf( "Buzz\n" ); } else { printf( "%d\n", i ); } #endif } return 0; }
Private
[
?
]
Run code
Submit