当前位置:文档之家› C语言试题

C语言试题

一、Select one answer from the four answers:(for each question, a total of 30 points)1.Which of the following expressiong is the equivalent to k=n++? ( ).A) k=n,n=n+1 B)n=n+1,k=n C)k=++n D)k+=n+12.What will be the printed output of the following program? ( ).main( ){ int x=10,y=10;printf("%d %d\n",x--,--y);}A)10 10 B) 9 9 C) 9 10 D) 10 93.Choose the correct output that following program produces. ( ).main(){ int x;x=-3+4*5-6; printf("%d",x);x= 3+4%5-6; printf("%d",x);x=-3*4%6/5; printf("%d",x);x=(7+6)%5/2; printf("%d",x);}A) 11 1 0 1 B) 11 -3 2 1 C) 12 -3 2 1 D)11 1 2 14. The printed output of the following program is ( ).#include <stdio.h>main(){ int y=10;do{y--;}while(--y);printf("%d\n",y--);}A) -1 B) 1 C) 8 D) 05. The printed output of the following program is ( ).#include <stdio.h>main(){ int i,b,k=0;for(i=1;i<=5;i++){ b=i%2;while(b-->=0) k++;}printf("%d, %d",k,b);}A) 3, -1 B) 8, -1 C) 3, 0 D) 8, -26.The correct expression to determain whether ch is a capital letter is( ).A) 'A'<=ch<='Z' B) (ch>='A')&&(ch<='Z')C) (ch>='A')&(ch<='Z') D) (ch>='A')AND(ch<='Z')7.Given a program as follows,the output will be( ) if data ADescriptor<CR>is keyed in when the program is running.#include <stdio.h>main(){ char c;int v0=0,v1=0,v2=0;do{switch( c=getchar()){ case 'a': case 'A':case 'e': case 'E':case 'i': case 'I':case 'o': case 'O':case 'u': case 'U': v1+=1;default: v0+=1; v2+=1;}}while(c!='\n');printf("v0=%d,v1=%d,v2=%d",v0,v1,v2);}A)v0=7,v1=4,v2=7; B)v0=8,v1=4,v2=8;C)v0=11,v1=4,v2=11; D)v0=12,v1=4,v2=12;8.Given the declarationsint a[][3]={1,2,3,4,5,6,7,8,9}the size of the first dimension of array a is ().A) 2 B) 3 C) 4 D) 59.The return type of the following program is( ).seed(double y){double z;z=x/2+5;return y;}A)int B)uncertain C)void D)float10. The following program will print out( ).main(){int m=5;if(m++>5) printf("%d\n",m);else printf("%d\n",m--);}A) 4 B) 5 C) 6 D) 711. Perform the following program. The printed output will be ( )if 3 is keyed in.#include<stdio.h>main(){int k;scanf("%d",&k);switch(k){case 1:printf("%d\n",k++);case 2:printf("%d\n",k++);case 3:printf("%d\n",k++);case 4:printf("%d\n",k++);break;default:printf("FULL!\n");}}A)3 B)4 C) 3 D) 44 512.The printed output of the next program is( ).#include<stdio.h>main(){int k=4,m=1,p;p=func(k,m);printf(“%d,”,p);p=func(k,m);printf(“%d\n”,p);}int func(int a,int b){static int m=0,i=2;i+=m+1;m=i+a+b;return m;}A)8,17 B)8,16 C)8,20 D)8,813.The valid function declaration in the following is ().A)double fun(int x,int y) B) double fun(int x;int y);C)double fun(int x,int y); D )double fun(int x, y);14. The printed output of the following program is( ). main(){ int a=100,x=10,y=20,ok1=5,ok2=0;if(x<y)if(y!=10)if(!ok1) a=1;else if(ok2) a=10;a=-1;printf("%d\n",a);}A) 1 B) 0 C) -1 D) 215.The printed output of the following program is( ). main(){int x[5]={2,4,6,8,10},*p,**pp;p=x; pp=&p;prin tf(“%d”,*p++);printf(“%3d\n”,**pp);}A)4 4 B)2 4 C)2 2 D)4 616.Given the declaration:int a[3][4];the legal reference to an element of array a is ( ).A) a[2][4] B)a[1,3] C)a[1+1][0] D)a(2)(1)17.Given the declaration:int a[5],*p;p=a;the correct reference to the element of array a is ( ).A) *&a[5] B)a+2 C) *(p+5) D) *(a+2)18. Give the following declarationsint k; int a[3][3]={1,2,3,4,5,6,7,8,9};the output of statementfor(k=0;k<3;k++) printf("%d",a[k][2-k]);is ( )A) 3 5 7 B) 3 6 9 C) 1 5 9 D)1 4 719.The printed output of the following program is ( ). main{ int a[6][6],i,j;for(i=1;i<6;i++)for(j=1;j<6;j++)a[i][j] = (i/j)*(j/i);for(i=1;i<6;i++){ for(j=1;j<6;j++)printf("%2d",a[i][j]);printf("\n");}}A)1 1 1 1 1 B)0 0 0 0 1 C)1 0 0 0 0 D)1 0 0 0 11 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 1 0 1 01 1 1 1 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 01 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 01 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 120.Give a structure defination and a structure variable s declaration as follows:structure student{ int no;char name[20];char set;struct{ int year;int month;int day;}birth;};if structure member birth is going to be initialized as Nov. 11 1984, the legal assignments in the following is ().A) year=1984;B) birth.year=1984;month =11; birth.month=11;day=11; birth.day=11;C)s.year=1984; D)s.birth.year=1984;s.month=11; s.birth.month=11;s.day=11; s.birth.day=11;二、Filling in Blanks:(1 points for each blank,total of 10 points)1. Given that a=3,b=2,c=1, the value of expression【1】2. Suppose letter A’s ASCII code is 65 in decimal. What’s the output 【2】of the following:printf(“%d”,’A’+’5’-’3’);3.Assume a, b and c are all of type int, after the evalution of the following expression, a=(b=4)+(c=2); the a’s value is 【3】, b’s value is 【4】.4.Let binary number x=11001101, if you want to set the leftmost 4 bits of x to 0-bits and leave the remaining bits unchanged by bitwise operation x&y, the binary number y needs to be 【5】5. The following program will print out 【6】.#include <stdio.h>main(){int i =0;while(i!=3){i++;}printf(“%d”,i);}6. The following program will print out 【7】.#include <stdio.h>main(){int i;for(i=0;i<5;i++){if(i= =2)continue;}printf(“%d”,i);}7. Given the declaration as follows:int m=5,y=2;the value of y after the evaluation of y+=y-=m*=y is 【8】8.Assume a is a variable of type int, after the evaluation of the following expression,a=25/3%3the value of a is 【9】9. Give the declarationint a[3]={1,2,3};the initializer for a[1] is 【10】三、Ture of False?(1 points for each blank,10 points)1.All variables must be given a type when they are declared. ( )2.The conditional test !e in while(!e); is equivalent to e= =0. ( )3.Like variables, constants have a type.( )4.Character constants are code using double quotes.( )5.In C language, any nonzero value represents logical value “true”. ( )6.The following for statement will loop 123 times( )for(x=0,y=0;(y=123)&&(x<4);x++,y++);7.Variables declared in a function are valid in the function only. ( )8. a=2>3?3:2; the value of a is 3.( )9.Assuming that the type of y is int, the expression (y%2)= =1 means “y is an odd number”.( )10.An expression statement is terminated with a period. ( )(2 points for each blank, a total of 4 points)1.The output result of the below program is【1】#include<stdio.h>main(){ int a,b,s=0;for(a=1,b=1;a<=100;a++){ if(b>=20) break;if(b%3==1){b+=3; continue;}b-=5;}printf(“a=%d\tb=%d\n”,a,b);}2. The output result of the below program is 【2】#include<stdio.h>int func(int a, int b){return (a+b);}main(){ int x=2,y=5,z=8,r;r=func(func(x,y),z);printf(“%d\n”,r);} Array五、Filling in the blanks and finish the program:(for each blank, a total of 26 points)1.The following Program will compute the value of 20items of the follow series:2/1,3/2,5/3,8/5,13/8,21/13,….Please fill in the blanks to complete the Program.#include<stdio.h>int main(){int n,t;float a=2,b=1,s=0;for(n=1;【1】;n++){s=【2】;t=a;a=【3】;b=t;}printf(“s=%f\n”,s);return 0;}2. The following Program is designed to output an array a with 4 elements in a line. Please fill in the blanks to complete the program.#include<stdio.h>int main(){int a[12],i;for(【4】;i<12;i++)scanf(“%d”,【5】);for(i=0;i<12;i++){if(【6】)printf(“\n”);printf(“%d”,【7】);}printf(“\n”);return 0;}3. The following function max_2 is designed to return the maximum of two numbers, Please fill in the blanks to complete the program.#include<stdio.h>【8】;int main(){int num1=10,num2=20;max-2(【9】, 【10】);printf("maximum = %d\n", num1);return 0;}void max_2(int *data1,int *data2){if(*data1<*data2 )【11】;}4.Enter an integer from the keyboard, the statistics of the number of bits. For example, input 12534, output 5; input -99, output 2; input 0, output 1.#include<stdio.h>int main(void){int number,count;count=0;printf("Enter an integer:\n");scanf("%d",&number);if(number<0)number=-number;do{number=【12】;count++;}while(【13】);printf("the integer is %d bits.\n",count);return 0;}(5 points for each title, a total of 20 points)1)Enter a number, Determine the parity number. Forinput “1” ,output “The number is odd” ; input “2”, output “The number is even”2) Write a program and type two positive integers a and n, seeking the sum of a + aa + aaa + aa .... a (the a total of n) . For example, the inputs 2 and 3, the output 246 (2 + 22 + 222).3) Compile and compose procedure , enter the radius and height , seek a cylinder volume (). Requirements definition and calling function cylinder(r,h), calculate the volume of a cylinder.4) Enter 5 integers, they will be stored in the array a, then x input number , and then in the array to find x, if found, output "Found!".otherwise, output "Not Found!".Input: 2 9 8 1 99Output: Found!Input: 2 9 8 1 67Output: Not Found!。

相关主题