Copy #include <stdio.h>
int main ( void )
{
int a = 10 ;
int b = 20 ;
if (a >= 5 )
{
printf( "first sentence\n" ) ;
printf( "second sentence\n" ) ;
}
if (b == 50 )
printf( "third sentence\n" ) ;
printf( "fourth sentence\n" ) ;
return 0 ;
}
Copy #include <stdio.h>
int main ( void )
{
int a;
a = 10 ;
printf( "(a==10) is %d \n" , (a == 10 )) ;
if (a == 10 )
{
printf( "code1\n" ) ;
}
if ( 5 )
{
printf( "code2\n" ) ;
}
if ( 0 )
{
printf( "code3\n" ) ;
}
if (a)
{
printf( "code4\n" ) ;
}
return 0 ;
}
月(1~12)を入力すると,下の表のように対応する季節(spring, summer, autumn, winter)を出力するプログラムを作れ.
Copy #include <stdio.h>
int main ( void )
{
int month , season;
printf( "month[1-12]=" ) ; scanf( " %d " , & month) ;
season = month / 3 ;
if (season == 1 ){
printf( "It's spring.\n" ) ;
}
else if (season == 2 ){
printf( "It's summer.\n" ) ;
}
else if (season == 3 ){
printf( "It's autumn.\n" ) ;
}
else {
printf( "It's winter.\n" ) ;
}
return 0 ;
}
大小2つの整数を入力し,小さい方で大きい方が割り切れたら"Multiple!"(倍数)と出力し,割り切れなければ余りを出力するプログラム.
Copy #include <stdio.h>
int main ( void )
{
int large , small , remainder;
printf( "Large number=" ) ; scanf( " %d " , & large) ;
printf( "Small number=" ) ; scanf( " %d " , & small) ;
remainder = large % small;
if (remainder == 0 ) printf( "Multiple!\n" ) ;
else printf( "Remainder= %d \n" , remainder) ;
return 0 ;
}
Copy #include <stdio.h>
int main ( void )
{
int a , b , c , min , max;
printf( "a=" ) ; scanf( " %d " , & a) ;
printf( "b=" ) ; scanf( " %d " , & b) ;
printf( "c=" ) ; scanf( " %d " , & c) ;
if (a > b){
max = a; min = b;
} else {
max = b; min = a;
}
if (c > max) max = c;
if (c < min) min = c;
printf( "Maximum= %d Minimum= %d \n" , max , min) ;
return 0 ;
}
Copy #include <stdio.h>
int main ( void ){
char input;
printf( "Input a character:" ) ;
scanf( " %c " , & input) ;
if (input >= 'A' && input <= 'Z' ){
printf( "upper\n" ) ;
} else if (input >= 'a' && input <= 'z' ){
printf( "lower\n" ) ;
} else {
printf( "error\n" ) ;
}
return 0 ;
}