練習問題/解答例/FizzBuzz/C++
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[練習問題/回答例]]
**FizzBuzz [#hc29b9d3]
#geshi(language=cpp, number){{
#include <iostream>
#include <sstream>
using namespace std;
int main( int argc, char** argv){
unsigned long limit;
if(argc < 2){
cout << "Input limit > ";
cin >> limit;
}else{
istringstream is(argv[1]);
is >> limit;
}
for( unsigned long i = 1; i <= limit; i++ ){
if( i % 15 == 0 ){
cout << "FizzBuzz" << endl;
}else if( i % 3 == 0 ){
cout << "Fizz" << endl;
}else if( i % 5 == 0 ){
cout << "Buzz" << endl;
}else{
cout << i << endl;
}
}
return 0;
}
}}
終了行:
[[練習問題/回答例]]
**FizzBuzz [#hc29b9d3]
#geshi(language=cpp, number){{
#include <iostream>
#include <sstream>
using namespace std;
int main( int argc, char** argv){
unsigned long limit;
if(argc < 2){
cout << "Input limit > ";
cin >> limit;
}else{
istringstream is(argv[1]);
is >> limit;
}
for( unsigned long i = 1; i <= limit; i++ ){
if( i % 15 == 0 ){
cout << "FizzBuzz" << endl;
}else if( i % 3 == 0 ){
cout << "Fizz" << endl;
}else if( i % 5 == 0 ){
cout << "Buzz" << endl;
}else{
cout << i << endl;
}
}
return 0;
}
}}
ページ名: