C语言练习题——if语句_c语言

1.下面代码执行的结果是:( )

#include <stdio.h>
int main()
{ 	
    int i = 0; 	
    for (i = 0; i<10; i++) 	
    { 		
        if (i = 5) 			
        printf("%d ", i); 
    } 	
    return 0; 
}


A.1 2 3 4 5 6 7 8 9 10

B.5 5 5 5 5 5 5 5 5 5

C.死循环的打印5

D.0 1 2 3 4 5 6 7 8 9

2.关于if语句说法正确是:( )



A.if语句后面只能跟一条语句

B.if语句中0表示假,1表示真

C.if语句是一种分支语句,可以实现单分支,也可以实现多分支

D.else语句总是和它的对齐的if语句匹配

3.关于switch说法不正确的是:( )



A.switct语句中的default子句可以放在任意位置

B.switch语句中case后的表达式只能是整形常量表达式

C.switch语句中case子句必须在default子句之前

D.switch语句中case表达式不要求顺序

4.试求func(1) = (      )

int func(int a) 
{     
    int b;    
    switch (a)    
    {         
          case 1: b = 30;       
          case 2: b = 20;         
          case 3: b = 16;         
          default: b = 0;    
    }     
   return b; 
}



A.30

B.20

C.16

D.0



5.switch(c)语句中,c不可以是什么类型( )



A.int

B.long

C.char

D.float



6.下面代码的执行结果是什么( )

#include <stdio.h> 
int main() 
{ 	
    int x = 3; 	
    int y = 3; 	
    switch (x % 2)
     { 	
         case 1: 		
         switch (y) 		
         { 		
             case 0: 			
                 printf("first"); 		
             case 1: 			
                 printf("second"); 			
             break; 		
             default:
                  printf("hello"); 		
     } 	
     case 2: 		
     printf("third"); 	
     } 	
     return 0; 
 }



A.secondthird

B.hello

C.firstsecond

D.hellothird

7.写代码将三个整数数按从大到小输出。



例如:

输入:2 3 1

输出:3 2 1

8.打印3的倍数的数



写一个代码打印1-100之间所有3的倍数的数字

9.求最大公约数



给定两个数,求这两个数的最大公约数

例如:

输入:20 40

输出:20