codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> using namespace std; void fizzbuzz1() { for( unsigned char ch = 1; ch < 101; ch++ ) { string output = ""; output += ( ch % 3 == 0 ) ? "fizz":""; output += ( ch % 5 == 0 ) ? "buzz":""; if( output.size() == 0 ) { cout << +ch; } else { cout << output; } cout << "\n"; } } void fizzbuzz2() { for( unsigned char ch = 1; ch < 101; ch++ ) { bool flg = false; if( ch % 3 == 0 ) { cout << "fizz"; flg = true; } if( ch % 5 == 0 ) { cout << "buzz"; flg = true; } if( !flg ) { cout << +ch; } cout << "\n"; } } void fizzbuzz3() { const char* outputs[] = { "", "fizz", "buzz", "fizzbuzz" }; for( unsigned char ch = 1; ch < 101; ch++ ) { unsigned char index = 0; if( ch % 3 == 0 ) { index++; } if( ch % 5 == 0 ) { index+=2; } if( index > 0 ) { cout << outputs[index]; } else { cout << +ch; } cout << "\n"; } } void fizzbuzz4() { const char* outputs[] = { "", "fizz", "buzz", "fizzbuzz" }; for( unsigned char ch = 1; ch < 101; ch++ ) { unsigned char index = 0; index += ( ch % 3 == 0 ); index += ( ch % 5 == 0 )*2; if( index > 0 ) { cout << outputs[index]; } else { cout << +ch; } cout << "\n"; } } int main() { fizzbuzz4(); return 0; }
Private
[
?
]
Run code
Submit