#include<iostream> using namespace std; int main( int argc, char** argv ){ int lim = 0; int i; sscanf( argv[ 1 ], "%d", &lim ); for( i = 1; i <= lim; i ++ ){ if( i % 15 == 0 ){ printf( "FizzBuzz" ); }else if( i % 3 == 0 ){ printf( "Fizz" ); }else if( i % 5 == 0 ){ printf( "Buzz" ); }else{ printf( "%d", i ); } printf( " " ); } return 0; }
#include<iostream> #include<math> using namespace std; int main( int argc, char** argv ){ int lim = 0; int i; bool isPrime = true; sscanf( argv[ 1 ], "%d", &lim ); for( i = 2; i < ( int )( sqrt( lim ) + 1.0 ); i ++ ){ if(( lim % i ) == 0 ){ isPrime = false; break; } } if( isPrime ){ printf( "%dは素数\n", lim ); }else{ printf( "%dは非素数\n", lim ); } return 0; }
おまけで素数列挙
#include<iostream> #include<math> using namespace std; int main( int argc, char** argv ){ int lim = 0; int i, j; bool isPrime; sscanf( argv[ 1 ], "%d", &lim ); if( lim == 0 ){ return -1; } printf( "%d ", 2 ); for( i = 3; i < lim; i ++ ){ isPrime = true; for( j = 2; j < ( int )( sqrt( i ) + 1.0 ); j ++ ){ if(( i % j ) == 0 ){ isPrime = false; break; } } if( isPrime ){ printf( "%d ", i ); } } return 0; }
#include<iostream> using namespace std; int main( int argc, char** argv ){ double target = .0; double result = .0; double temp; int i, j, k; char *str1, *str2; sscanf( argv[ 1 ], "%lf", &target ); sscanf( argv[ 2 ], "%d", &k ); str1 = ( char* )malloc( k ); str2 = ( char* )malloc( k ); if( target == .0 ) return -1; for( i = 9; i >= 0; i -- ) if( i * i <= ( int )( target )) break; sprintf( str1, "%d.", i ); for( j = 0; j < k; j ++ ){ for( i = 9; i >= 0; i -- ){ sprintf( str2, "%s%d", str1, i ); sscanf( str2, "%lf", &temp ); if(temp * temp <= target ) break; } strcpy( str1, str2 ); } sscanf( str1, "%lf", &result ); sprintf( str2, "%%lf,%%.%dlf", k ); printf( str2, target, result ); return 0; }
#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;
} }}