1、C语言期末考试试题南昌航空大学C语言期末考试试题-南昌航空大学C语言期末考试试题 南昌航空大学一、单选题(1) 若要定义一个具有5个元素的整型数组,以下错误的定义语句是A)int a5=0;B)int b=0,0,0,0,0;C)int c2+3;D)int i=5,di;(2)以下选项中可用作C程序合法实数的是A).1e0 B)3.0e0.2C)E9 D)9.12E(3)有以下程序段char name20;int num;scanf(name=%s num=%d,name,&num);当执行上述程序段,并从键盘输入:name=Lili num=1001后,name的值为A)LiliB)nam
2、e=LiliC)Lili num=D)name=Lili num=1001(4)if语句的基本形式是:if(表达式) 语句,以下关于“表达式”值的叙述中正确的是A)必须是逻辑值 B)必须是整数值C)必须是正数 D)可以是任意合法的数值(5)若i和k都是int类型变量,有以下for语句for(i=0,k=-1;k=1;k+) printf(*n);下面关于语句执行情况的叙述中正确的是A)循环体执行两次B)循环体执行一次C)循环体一次也不执行D)构成无限循环(6)有以下程序#include void main() int x=1,y=0;if(!x) y+;else if(x=0)if (x) y
3、+=2;else y+=3;printf(%dn,y);程序运行后的输出结果是A)3 B)2 C)1 D) 0(7)设有如下函数定义int fun(int k) if (k1) return 0;else if(k=1) return 1;else return fun(k-1)+1;若执行调用语句:n=fun(3);,则函数fun总共被调用的次数是确语句是A)scanf(%f,&x6); B)scanf(%lf,*(x+6);C)scanf(%lf,p+6); D)scanf(%lf,p6);(15)有以下程序段#include void main() while( getchar()!=n
4、);以下叙述中正确的是A)此while语句将无限循环B)getchar()不可以出现在while语句的条件表达式中C)当执行此while语句时,只有按回车键程序才能继续执行D)当执行此while语句时,按任意键程序就能继续执行(16)若有定义语句:char s310,(*k)3,*p;,则以下赋值语句正确的是A)p=s; B)p=k; C)p=s0; D)k=s;(17)有以下程序#include void fun(char *c) while(*c) if(*c=a&*c=z) *c=*c-(a-A);c+;void main() char s81;gets(s); fun(s); puts
5、(s):当执行程序时从键盘上输入Hello Beijing,则程序的输出结果是A)hello beijing B)Hello Beijing C)HELLO BEIJING D)hELLO Beijing(18)有以下程序#include void main() char a30,b30;scanf(%s,a);gets(b);printf(%sn %sn,a,b);程序运行时若输入:how are you? I am fine则输出结果是A)how are you? B)how are you? C)how are you? I am fine D)howare you? I am fine
6、(19)有以下程序#include int fun (int x,int y) if (x!=y) return (x+y)/2);else return (x);void main() int a=4,b=5,c=6;printf(%dn,fun(2*a,fun(b,c);程序运行后的输出结果是A)3 B)6 C)8 D)12(20)有以下程序#include struct S int a,b;data2=10,100,20,200;void main() struct S p=data1;printf(%dn,+(p.a);程序运行后的输出结果是A)10 B)11 C)20 D)21二、读
7、程序写结果(1)阅读下列程序:#include void main()int a; a=(int)(double)(3/2)+0.5+(int)1.99*2); printf(%dn,a);上述程序的输出结果是(2)阅读下列程序:#include int main() int i; int branch; double bonus,bon1,bon2,bon4,bon6,bon10; bon1=100000*0.1; bon2=bon1+100000*0.075; bon4=bon2+200000*0.05; bon6=bon4+200000*0.03; bon10=bon6+400000*0
8、.015; scanf(%d,&i); branch=i/100000; if (branch10) branch=10; switch(branch) case 0:bonus=i*0.1;break; case 1:bonus=bon1+(i-100000)*0.075;break; case 2: case 3: bonus=bon2+(i-200000)*0.05;break; case 4: case 5: bonus=bon4+(i-400000)*0.03;break; case 6: case 7: case 8: case 9: bonus=bon6+(i-600000)*0
9、.015;break; case 10: bonus=bon10+(i-1000000)*0.01; printf(奖金是 %10.2fn,bonus); return 0; 输入“234000”,上述程序的输出结果是(3)阅读下列程序:#include #include int main()double x1,x0,f,f1; x1=1.5; do x0=x1; f=(2*x0-4)*x0+3)*x0-6; f1=(6*x0-8)*x0+3; x1=x0-f/f1; while(fabs(x1-x0)=1e-5); printf(The root of equation is %5.2fn,
10、x1); return 0; 上述程序的输出结果是(4)阅读下列程序:#include int main() int a11=1,4,6,9,13,16,19,28,40,100; int temp1,temp2,number,end,i,j; scanf(%d,&number); end=a9; if (numberend) a10=number; else for (i=0;inumber) temp1=ai; ai=number; for (j=i+1;j11;j+) temp2=aj; aj=temp1; temp1=temp2; break; for (i=0;i11;i+) pri
11、ntf(%5d,ai); printf(n); return 0; 输入“50”,上述程序的输出结果是(5) 阅读下列程序:#include struct student int num; char name20; float score; ; int main() struct student stu3=10101,Zhang,78,10103,Wang,98.5,10106,Li,86; struct student temp; const int n=3; int i,j,k; for(i=0;in-1;i+) k=i; for(j=i+1;jstuk.score) k=j; temp=
12、stuk;stuk=stui;stui=temp; for(i=0;in;i+) printf(%6d %8s %6.2fn,stui.num,stui.name,stui.score); printf(n); return 0;上述程序的输出结果是(6) 阅读下列程序:#include int main()void copy_string(char *from, char *to); char *a=a teacher.; char b=a student.; char *p=b; printf(string a=%snstring b=%sn,a,b); printf(ncopy string a to string b:n); copy_string(a,b); printf(string a=%snstring b=%sn,a,b); return 0;void copy_string(char *from, char *to) for(;*from!=0;from+,to+) *to=*from; *to=0; 上述程序的输出结果是三、改写程序1.输出结果如图A所示,修改程序,要求(1)不输出第一行的空行;(2)“3”这行输出空行,如图B所示。 #include int main() int i,
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1