文档详情

c第四章 控制结构.doc

发布:2017-01-04约4.31千字共5页下载文档
文本预览下载声明
第四章 控制结构 一、选择题: 结构化程序模块不具有的特征是____.   A)只有一个入口和一个出口   B)要尽量多使用goto语句   C)一般有顺序、选择和循环三种基本结构   D)程序中不能有死循环 C语言中,逻辑“真”等价于____.   A)整数1 B)整数0  C)非0数 D)TRUE 3)以下4条语句中,有语法错误的是____.   A)if(ab) m=a;  B)if(ab) m=b;   C)if((a=b)=0) m=a;  D)if((a=b;)=0) m=a; 4)若i, j均为整型变量,则以下循环____. for(i=0,j=2; j=1; i++,j--) printf(%5d, %d\n, i, j);   A)循环体只执行一次  B)循环体执行二次 C)是无限循环     D)循环条件不合法 5)以下程序段,执行结果为____. a=1; do { a=a*a; }while(!a); A)循环体只执行一次  B)循环体执行二次 6)C语言中while与do-while语句的主要区别是____. A)do-while的循环体至少无条件执行一次 B)do-while允许从外部跳到循环体内   C)while的循环体至少无条件执行一次 D)while的循环控制条件比do-while的严格 7)语句while (!a);中条件等价于____. A)a!=0  B)~a  C)a==1  D)a==0 8)以下程序的运行结果为____. #include stdio.h main( ) { int i=1,sum=0; while(i=100) sum+=i; i++; printf(1+2+3+...+99+100=%d, sum); } A)5050 B)1   C)0   D)程序陷入死循环 9)以下程序的运行结果为____. #include stdio.h main( ) { int sum,pad; sum=pad=5; pad=sum++; pad++; ++pad; printf(%d\n, pad); } A)7 B)6    C)5    D)4 10)以下程序的运行结果为____. #include stdio.h main( ) { int a=2,b=10; printf(a=%%d,b=%%d\n, a,b); } A)a=%2,b=%10 B)a=2,b=10 C)a=%%d,b=%%d D)a=%d,b=%d 11)为了避免嵌套的if-else语句的二义性,C语言规定else总是____.   A)与缩排位置相同的if组成配对关系   B)与在其之前未配对的if组成配对关系   C)与在其之前未配对的最近的if组成配对关系   D)与同一行上的if组成配对关系 12)对于for(表达式1; ;表达式3)可理解为____.   A)for(表达式1; 0 ;表达式3)   B)for(表达式1; 1 ;表达式3)   C)for(表达式1;表达式1;表达式3) D)for(表达式1;表达式3;表达式3) 二、填空题: 1.下面程序的功能是计算n!。 #include stdio.h main( ) { int i, n; long p; printf ( Please input a number:\n ); scanf (%d, n); p=_____________; for (i=2; i=n; i++) ________________; printf(n!=%ld, p); 2.下面程序的功能是:从键盘上输入若干学生的成绩,统计并输出最高和最低成绩,当输入负数时结束输入。 #include stdio.h main ( ) { float score, max, min; printf ( Please input one score:\n ); scanf (%d, score); max=min=score; while ( _____________ ) { if (scoremax) max=score; if ( ______________ ) min=score; printf ( Please input another score:\n ); scanf (%d, score); } printf(\nThe max score is %f\nT
显示全部
相似文档