您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页北航c语言期末试题

北航c语言期末试题

来源:华佗小知识
PARTⅠ: GIVE A DECISION. circle „T‟ for true and „F‟ for false(10marks, 1

mark per point)

1. The value of the expression 8==8==8 is 1. T

2. An array name is the address of the first element of the array. T

3. typedef merely adds a new name for some existing type. T

4. Evaluate !(1 &&0 ||!1) as true or false T

5. The null character „\\0‟ terminates all character strings.

6. The output of the following is *successful----- *

7. Assuming enum week { MON, TUE=2, WES, THUR, FRI, SAT, SUN}; the value of SAT is 6 . T F

8. In C, the value of the expression 9/8 is 0 T F

9. For an array declaration a[][2]={0,1,2,3,4,5,6,7,8}, the row size is 4. T F

10. Automatic and register variables have undefined initial values.

T F

main() {printf(“*%15.10s*”,” successfully”);}

T F

F F F F

T F

PARTⅡ: SINGLE CHOICE QUESTIONS(40marks, 2marks per question)

1. The C program consists of ______________.

A)a main function and some subroutines B)functions C)procedures D)subroutines.

2. Which of the following constant is invalid?______________

A) 0818 B) 2.5e-2 C) 2f D) 0xA5

3. What does strcat (an_array, “this”); do?_______________ A) finds “this” in an_array

B) adds “this” to the end of an_array

C) compares an_array and “this” D) copies “this” into an _array

4. Which operator has the highest precedence?____________

A.+= B.++ C.? : D.[ ]

5. Which of the following operator can be used as an unary-operator? ___________

A.+= B.% C.* D./

6. Which one is wrong if it is used as a character constant? _____________

A.”1” B.‟1‟ C.1 D.‟\\n‟

7. According to the declaration: int a[10], *p=&a[2]; the last element of the array a is ______.

A.a[10] B.p[9] C.p[8] D.p[7]

8. Assuming that the value of grade is „C‟, predict what gets printed_________.

switch(grade)

{ case‘A’:printf(“*”); case‘B’:printf(“**”); case‘C’:printf(“***”); case‘D’:printf(“****”); default :printf(“#”);

B) ****

C) ***#

D) *******#

} A) ***

9. For the variable names below, which group is the one whose all variable names are invalid?__________

A)Printf B)sort_1 row string_to_float IF Enum

C) register D) DOUBLE

1P book_price t.abc A2B

10 As we know that a library function double acos(double x) x(1,1) which is included in “math.h”. which one of the following works properly?___________

A #include “stdio.h” int y=acos(2);

B #inlcude “math.h” int z; z=acos(0.5); C #include “math.h” double y,x; y=acos(x);

D #include “math.h” int x,z; z=acos(x=0.3);

11. Assuming that the user of a program is asked to enter a day number (1-7) into an integer

variable called day. Which of the following while loops is valid?____________ A. while (day >= 1 || day <= 7){ printf(\"ERROR 1 - 7 only, enter again: \"); scanf(“%d”, &day); } B. while (day >= 1 && day <= 7){ printf(\"ERROR 1 - 7 only, enter again: \"); scanf(“%d”, &day); } C. while (day < 1 || day > 7){ printf(\"ERROR 1 - 7 only, enter again: \"); scanf(“%d”, &day); } D. while (day <= 1 || day >= 7){ printf(\"ERROR 1 - 7 only, enter again: \"); scanf(“%d”, &day); }

12. Which one is wrong? ___________

A.char str[10]; str=\"string\"; B.char str[ ]=\"string\";

C.char *p=\"string\";

D.char *p; p=\"string\";

13. According to the declaration: int p[5], *a[5]; Which of the following expression is correct?______________

A.p=a B.p[0]=a C.*(a+1)=p D.a[0]=2

14. Predict what gets printed: __ .

1

void swap(int *a, int *b) { }

main() { int a=3, b=6, *x=&a, *y=&b; }

A) 6 3 B) 3 6 C) compiling error

D) 0 0

15. Predict what gets printed: _________________

# include

int a=10, b, x, y; void num ()

{ int a=15,b=10; x = a - b; y = a + b; printf(\"%d, %d\\n”, x, y): } main ()

{ a= 7,b =5; num (); }

A) not for sure B) 12,2 C) 5,25 D) 0,20

16. Assuming #define sum(a, b) a + b predict the value of: 5 * sum(3 + 1, 2) ____________. A. 30

B. 18

C. 22

D. none of the above

swap(x,y);

printf(\"%d %d\int *k;

k=a; a=b; b=k;

17. What is the main problem with the following: __________ int *ip;

for (*ip = 0; *ip < 5; *ip++) ;

A) Nothing is wrong.

B) It dereferences(间接引用) an uninitialized pointer. C) It does nothing useful.

D) It contains implementation dependent problem(s).

18. Predict the output from: __________

if (5 < 4)

if (6 > 5)

putchar('1');

else if (4 > 3)

putchar('2'); else

putchar('3'); putchar('4'); A) 4

2

B) 2

C) 24

D) 4 or 24, depending upon the implementation.

19. What is the main problem with the following?______________ ① main( )

② { int a[10],i; ③ for (i=0;i<10;i++) ④ scanf (“%d”,a[i]); ⑤ ⑥ ⑦ }

for (i=0;i<10;i++)

a[i]= a[i+1];

A) Nothing is wrong. B) Line④ is wrong. C) Line⑥ is wrong.

D) Both line④ and ⑥ are wrong.

20. The program segment (程序段) below reverses(逆序) the string s in the place, which one is written correctly?_______________ A)for (i = 0, j = strlen(s); i < j; i++, j--) c = s[i], s[i] = s[j], s[j] = c; B) for (i = 0, j = strlen(s)-1; i < j; i++, j--) c = s[i], s[i] = s[j], s[j] = c; C) for (i = 0, j = strlen(s)-1; i < j; i++, j--) c = s[i]; s[i] = s[j]; s[j] = c; D) for (i = 0, j = strlen(s); i < j; i++, j--) c = s[i]; s[i] = s[j]; s[j] = c;

PARTⅢ: FILL IN THE BLANKS (20marks, 1 mark per blank)

1. Write a conditional expression to calculate the maximum of x and y.___________.

2. Predict the value of the expression ~ (10^2) &7 ___________.

3. Predict what gets printed______________.

char *st[ ]={\"ONE\printf(\"%s, %c\\n\

4. Predict what gets printed._____________

int f (int x) {

if(x<=1) return 1;

else return f(x-1)+f(x-2); }

void main ( )

{ printf(\"%d\}

5. After running the program below , if the output (z) is 9.00,please predict the initial value of x. main() { int a=7, b=2;

3

float x= __________ , y=1.1,z; z=a/2+b*x/y+1/2; printf(\"%.2f\\n\

}

6. Here is a declaration: union { unsigned long l_num; unsigned char c_num[4]; } d;

Assuming that d.l_num=0x36c3a1f, what is the value of d.c_num[2]?__________. How many bytes does the variable d hold in the memory? __________

7. Predict what gets printed: __ .

main() { int x;

for (x=1; x<10; x++) { if (x<3) continue;

x*=2 ;

printf(“#”); }

}

9. Predict what gets printed: _ .. void fun()

{ static int a=1;

a*=a+1; printf(“%d,”,a); }

main() { int cc;

for(cc=1;cc<4;cc++) fun(); }

10. Predict what gets printed:______________.

main() { int array [] = {2, 8, 3, 11, 13, 2, 8, 2}; int k; int total = 0; for ( k = 0; k < 8; k++ ) { if ( array [k] % 2) break; total += array [k]; } printf ( “%d ”, total ); }

11. Assuming int a[3][3]={2,4,6,8,10,12,14,16}; the value of *(a[2]+2) is ___________.

12. Here is a binary search function that decides if a particular value occurs in the sorted array v. int binsearch(int x, int v[], int n) /* binsearch: find x in v[0] <= v[1] <= ... <= v[n-1] */ { int low, high, mid;

low = 0; high = n - 1; while (lowmid = (low+high)/2;

if (____________) high = mid -1 ; else if (____________) low = mid+1; else /* found match */ return mid; }

return -1; /* no match */ }

4

13. Function itoa: convert n to characters in s , fill in the blanks void itoa(int n, char s[]) { int i, sign;

if ((sign = n) < 0) /* record sign */

n = -n; /* make n positive */ i = 0;

do { /* generate digits in reverse order */

s[i++] = _______________; /* get next digit */ } while ((__________) > 0); /* delete it */ if (sign < 0) s[i++] = '-'; s[i] = '\\0'; reverse(s); }

8. Write the prototype(原型) for the following C function

Function name : max Return data type: int

Input data types: two input values of type int

________________________

22. Predict what gets printed:_________________.

void melon (int g, int * h); int main (void) { int a = 1, b = 2; melon ( a, &b ); printf ( \"a = %d, b = %d\ a, b ); }

void melon (int b, int * c) { b++; *c = *c + b; }

23. Here is a function month_day which converts the day of the year into the day of month. void month_day(int year, int yearday, int *pmonth, int *pday)

{ static int day_tab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31}, {0,31,29,31,30,31,30,31,31,30,31,30,31}}; int k, leap;

leap = year % 4==0 && year % 100 != 0 || year % 400 == 0; for(k=1; yearday > day_tab[leap][k]; k++)

____________________; *pmonth = _____________ ; *pday = yearday; }

25. The program below calculates the value of s = 1/1! + 1/2! + 1/3! + ……+ 1/n!. Assuming that the input is positive(n>0), fill in the blanks to complete the program. #include void main( ) { int j, k, n; float f, s;

scanf(\"%d\ s=0;

for (k=1 ; k<=n; k++){ f=1 ;

for(j=1; j<=k; j++)

____________ ;

s=s+1.0/f;

5

}

printf(\"sum=%f\\n\}

PART Ⅲ: PROGRAMMING(30marks)

1. Write a program to print all the numbers which are between 1 to 100, can be divided by 6 and

whose unit‟s places(个位) are 2. (10marks)

2. Write a function to change a matrix (矩阵) with m rows and n columns into the matrix with

n rows and m columns. (10 marks)

3.Create a structure called stud that includes 4 pieces of information as data members——student‟s number and three subject scores(学号和三科成绩), Suppose there are 6 students whose information are {1001, 88,90,74} , {1002,69,66,}, {1003,87,74,70}, {1004,60,80,66}, {1005,95,84,87}, {1006,90,93,82}, write a program to do the following :

ⅰ) print out every students‟ information and their average scores. ⅱ) Sort the average scores in descending order(降序). (10 marks)

6

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务