2008年北航C语言期末试题
- 格式:doc
- 大小:68.00 KB
- 文档页数:5
北京航空航天大学《C语言程序设计》课程考试试卷注意事项: 1、本试卷满分100分;考试时间:90分钟;考试形式:开卷2、请将答案一律写在答题纸上,试卷上作答无效3、考试结束后,考生将试卷及答题纸一并交回4、请将条形码贴在答题纸的指定位置学习中心______________姓名____________学号____________一、单项选择题(本大题共10小题,每小题2分,共20分)1、设有定义语句“char s[]=”123”;”,则表达式“s[3]”的值是______。
()A.' 1' B.'3'C.'\0' D.存在语法错误2、凡是函数中未指定存储类别的局部变量,其隐含的存储类别为______。
()A.自动(auto) B.静态(static)C.外部(extern) D.寄存器(register)3、已知:char w; int x; float y; double z;,则表达式w*x+z-y结果的类型是______。
()A.float B.charC.int D.double4、当声明一个结构变量时,系统分配给它的内存是______。
()A.各成员所需内存量的总和B.结构中第一个成员所需内存量C.成员中占内存量最大者所需的容量D.结构中最后一个成员所需内存量5、C语言中的简单数据类型包括______。
()A.整型、实型、逻辑型B.整型、实型、字符型C.整型、字符型、逻辑型D.整型、实型、逻辑型、字符型6、合法的数组说明语句是______。
()A.int a[]="string";B.int a[]={0,1,2,3,4,5};C.char a="string";D.char a[5]={'0','1','2','3','4','5,};7、定义int i=1;,执行语句while(i++<5);后,i的值为______。
《 C 程序设计》期末考试卷一、选择题 (20分) 1, 下列运算符中最高优先级的运算符是A) && B) % C) -= D)!2, 对定义语句int a[]={1,2,3,4,5,6,7,8,9,10},*p=a,i=5;数组元素地址的正确表示是A)&(a+1) B)a++ C)&p D)&p[i]3, 以下结构定义,请指出不正确赋值语句是struct date{int month;int day;int year;};struct student{int num;char name[20];char sex;struct date birthday;float score;char addr[30];}stu1,stu2;A) stu1.num=10; B) stu1.score+=stu2.score;C) stu1=stu2; D) stu1.birthday.month=12;4,以下程序:#include <stdio.h>void main(){FILE *fp;fp1=fopen(“f1.txt”,”w”);fprintf(fp,”abc”);fclose(fp);}若文本文件f1 .txt中原有内容为good,则运行以下程序后文件f1.txt中的内容为A) abc B)abcd C) goodabc D) abcgood5,以下程序的运行结果是int f(int i){static int n=1;return n=n*i;}int main(){for (i=1;i<5;i++) printf(“%3d”,f(i));printf(“\n”);}A)1 2 3 4 B)1 2 6 24 C)1 2 4 6 D)1 3 6 24二、填空题 (30分)1, 若有定义double x; (5分)(1)使指针p可以指向变量x的定义语句是_________________(2)使指针p指向变量x的赋值语句是________________(3)通过指针p给变量x读入值的scanf函数调用语句是________________(4)通过指针p给变量x赋值语句是___________________(5) 通过指针p输出x的值的语句是____________________2,以下函数用以求x的y次方。
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 F2. An array name is the address of the first element of the array. T F3. typedef merely adds a new name for some existing type. T F4. Evaluate !(1 &&0 ||!1) as true or false T F5. The null character …\0‟ terminates all character strings. T F6. The output of the following is *successful----- *main() {printf(“*%15.10s*”,” successfully”);}T F7. Assuming enum week { MON, TUE=2, WES, THUR, FRI, SAT, SUN};the value of SAT is 6 . T F8. In C, the value of the expression 9/8 is 0 T F9. For an array declaration a[][2]={0,1,2,3,4,5,6,7,8}, the row size is 4. T F10. Automatic and register variables have undefined initial values. T FPARTⅡ: SINGLE CHOICE QUESTIONS(40marks, 2marks per question)1. The C program consists of ______________.A)a main function and some subroutines B)functionsC)procedures D)subroutines.2. Which of the following constant is invalid?______________A) 0818 B) 2.5e-2 C) 2f D) 0xA53. What does strcat (an_array, “this”); do?_______________A) finds “this” in an_arrayB) adds “this” to the end of an_arrayC) compares an_array and “this”D) copies “this” into an _array4. 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]switch(grade){ case‘A’:printf(“*”);case‘B’:printf(“**”);case‘C’:printf(“***”);case‘D’:printf(“****”);default :printf(“#”);}A) *** B) **** C) ***# D) *******#9. For the variable names below, which group is the one whose all variable names are invalid?__________A)Printf B)sort_1row string_to_floatIF EnumC) register D) DOUBLE1P book_pric et.abc A2B10 As we know that a library function double acos(double x) )1,1(-x 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 integervariable 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]=214. Predict what gets printed: __ .void swap(int *a, int *b){ int *k;k=a; a=b; b=k;}main(){ int a=3, b=6, *x=&a, *y=&b;swap(x,y);printf("%d %d", a, b);}A) 6 3 B) 3 6 C) compiling error D) 0 015. Predict what gets printed: _________________# include <stdio. h>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,2016. Assuming #define sum(a, b) a + b predict the value of: 5 * sum(3 + 1, 2) ____________.A. 30B. 18C. 22D. none of the above17. 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');elseputchar('3');putchar('4');A) 4B) 2C) 24D) 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;PAR TⅢ: 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","TWO","THREE","FOUR"};printf("%s, %c\n", *(st+2), **st+1);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", f(4));}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;float x= __________ , y=1.1,z;z=a/2+b*x/y+1/2;printf("%.2f\n", z );}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 (low<high) {mid = (low+high)/2;if (____________) high = mid -1 ;else if (____________) low = mid+1;else /* found match */return mid;}return -1; /* no match */}13. Function itoa: convert n to characters in s , fill in the blanksvoid 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 functionFunction name : maxReturn data type: intInput 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 <stdio.h>void main( ){ int j, k, n;float f, s;scanf("%d", &n);s=0;for (k=1 ; k<=n; k++){f=1 ;for(j=1; j<=k; j++)____________ ;s=s+1.0/f;}printf("sum=%f\n", s);}PART Ⅲ: PROGRAMMING(30marks)1.Write a program to print all the numbers which are between 1 to 100, can be divided by 6 andwhose unit‟s places(个位) are 2. (10marks)2. Write a function to change a matrix (矩阵) with m rows and n columns into the matrix withn 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,89}, {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)。
北航《C语言程序设计》答案北航《c语言程序设计》在线作业一单项选择和判断问题一、单选题(共15道试题,共60分。
)1.以下叙述中正确的是a、预处理命令行必须位于源文件的开头。
B.源文件的一行上可以有多个预处理命令。
C.宏名称必须用大写字母表示d.宏替换不占用程序的运行时间正确答案:d2.以下选项试图描述一个新的类型名称,其中正确的名称是a.typedefv1int;b、typedefv2=int;c、类型定义tv3;d、 typedefv4:int;正确答案:C3.c语言对嵌套if语句的规定是:else总是与()配对。
a.其之前最近的ifb.第一个ifc、其上一个最近的IFD没有其他的,如果具有相同的缩进位置,正确答案是:c4.已知:#definen3;执行语句i=n*3;后,i=_______.a.3b.6c.9d、以上这些都不正确。
正确答案:C5.以下选项中可作为c语言合法常量的是a.-8b.-080c.-8e1.0d.-80.0e正确答案:a6.以下不正确的c语言标识符是_____。
a.abcb.abcc.a_bcd.ab.c正确答案:D7.数组int**a[3][4]占据多大空间a、 64b。
12c。
48d。
一百二十八正确答案:c8.已知:intx,a,B;以下选项中错误的if语句是_;。
()a.if(a=b)x++;b.if (a)=正确答案:b9.以下可以正确表示字符类型常量为___。
a、 \b。
?Tc、 \d.297正确答案:b10.表达式:10=9的值为()a.trueb非零值c.0d一正确答案:d11.在C语言中,形式参数的默认存储类型是()a.autob registerc。
静力学。
外人正确答案:a12.假设在C语言中,一个int数据在内存中占用2个字节,那么无符号int数据的值范围是_u。
a、 0~255b。
0~32767c。
0~65535d.0~2147483647正确答案:c13.有以下声明:intb;charc[10];,正确的输入语句是a.Scanf(\b.Scanf(\c.Scanf(\d.Scanf)(\正确答案:b)14.为了避免嵌套的条件分支语句的二义性,c语言规定,c程序中的else总是与()组成配对关系。
安徽大学2008----2009学年第二学期C语言程序设计期末机考试题一、单项选择题(30分,每题2分)每小题的四个选项中只有一个符合题目要求,请将正确选项前字母填在括号中。
1.若int a[][3]={1,2,3,4,5,6};则a[1][0]的值是【______】。
AA. 4B. 2C. 1D. 52.执行下列程序段后,变量k的值是【______】。
Aint k=3, s[2];s[0]=k;k = s[1]*10;A)不确定B)0C)10 D)303.执行下列程序段后,变量k的值是【______】。
Cint k=3, s[2]={1};s[0]=k;k = s[1]+10;A)不确定B)0C)10 D)304.下面程序的输出结果是【______】。
C#include <stdio.h>void main(void){int i, a[10];for(i=9;i>=0; i--)a[i]=10-i;printf("%d%d%d\n",a[2],a[5],a[8]);}A)258 B)741C)852 D)3695.下面程序的输出结果是【______】。
B#include <stdio.h>void main(void){int a[3][3]={1,2,3,4,5,6,7,8,9},i;for(i=0;i<3; i++)printf("%d ",a[i][2-i]);}A)1 5 9 B)3 5 7C)1 4 7 D)3 6 96.下面程序的输出结果是【______】。
C#include "stdio.h"void fun(int a[]){int i;for(j=0;j<5; j++)a[j]=j;}void main(void){int num[]={5,6,7,8,9}, i;fun(num);for(i=0;i<5; i++)printf("%d ", num[i]);}A. 56789B. 98765C. 01234D. 432107.下面程序的输出结果是【______】。
2008年07级C程序设计期末考试卷(A)[注意] 所有答案写在单张的答题卷上。
一、判断题(本题共10分,每小题1分,用A表示正确,用B表示错误。
)(1) C语言程序的变量必须先定义再使用。
(2) do-while语句构成的循环不能用其他语句构成的循环来代替。
(3) C语言规定,函数的实参应与其对应的形参类型一致。
(4) C语言认为名为Student和student的变量是不同变量。
(5) 当两个字符串所包含的字符个数相同时,才能比较两个字符串的大小。
(6) 如果定义了int a[10],那么使用语句a[10]=10可以给数组元素a[10]初始化。
(7) 用关键字static声明的变量是全局变量,在整个程序的全部执行过程中都占用存储单元。
(8) 如果a=1,b=2,c=3,d=4则表达式a>b?c:d的值等于3。
(9) 如果a=15,那么执行a=a>>2以后,a的值就变成了3。
(10) 结构体成员的类型可以是另外一种结构体类型。
二、单选题(本题共20分,每小题2分)(11) 假设有以下定义:int a=0xAA,b=0x55,则a & b 的值为:________。
[A] 0x0 [B] 0xff[C] 0x01 [D] 0xAA(12) 假设有以下定义:int a[5]={1,2,3,4,5},i=3,*p=a , *q=a; 则不能正确执行的语句是________。
[A] i=*p +*q; [B] a=i;[C] *p = *(a+i); [D] i = *p**(q+2);(13) 以下有关宏定义的叙述,正确的是________。
[A]宏名必须用大写字母表示[B]带参数的宏就是一个函数[C]宏名不具有类型[D]宏定义和其它C语句,其末尾要加分号(14) 若用数组名作为函数调用时的参数,则实际上传递给形参的是________。
[A] 数组第一个元素的值[B] 数组元素的值[C] 数组的首地址[D] 数组名1第页(共7 页)(15) 如果在用户的程序中要使用C库函数中的数学函数时,应在该源文件中使用的include命令是________。
院(系):专业:年级:学生姓名:学号:-------------------------------------------------密----------------------------------封-----------------------------线---------------------------------------------------------第 1 页(共 3 页)------------------------------------------------- 密 ---------------------------------- 封 ----------------------------- 线 ---------------------------------------------------------第 2 页共 3 页------------------------------------------------- 密 ---------------------------------- 封 ----------------------------- 线 ---------------------------------------------------------第 3 页(共 3 页)2007–2008学年第二学期期末考试试卷(A卷)课程名称: 面向对象程序设计课程编号:任课教师:一、单项选择题:(共20题,每小题2分,共40分)1. B 2. C 3. C 4. A 5. A 6. B 7. B 8. C 9. B 10. D 11. C 12. D 13. D 14. B 15. C 16. D 17. B 18. A 19. A 20. A二、填空题:(共10题,每小题1分,共10分)21.true ,false 1 ,0 22.内联函数,编译,执行时间23.this 24.new25.继承26.私有,私有,不可访问27.虚函数28.基类指针或引用三、程序改错题:(共2题,每题5分,共10分)29.【答】【答】错误处标号如下:①///************************************************* 程序文件名: p1_2.cpp **************************************************/#include <iostream>;④using std::endl;⑤void main( )⑥float num1, num2, num3; //定义三个数cin ⑦<< num1 << num2<<num3;cout >> ⑧“The average is:”⑨>> setw(30) ⑩>>(num1+num2+num3)/3>> endl;}①行注释符号//将块注释的头/*注释掉了,使得块注释的尾*/没有相应的头与之匹配;②关键字Using中包含了大写字母,应改为using;③using namespace std不是预处理指令,要以分号结尾;④#include <iostream> 是预处理指令,不能以分号结尾,而且要作为程序的开头行⑤使用了using namespace std,就不必单独使用std::endl;⑥void main() 后少了{;⑦cin应与提取操作符>>连用;⑧cout应与插入操作符<<连用;⑨“The average is:”为全角引号,应改为英文;⑩使用setw(30) 应包含头文件iomanip30.【答】①int a(0),b(0); //错误,数据成员的初始化必须通过构造函数实现改正:int a,b;②A x(2,3), y(4); //错误,对象y的初始化与已定义的构造函数参数表不匹配,可重载一个构造函数对对象y进行初始化。
《C 语言程序设计》期末考试试卷学号:姓名:分数:一、单项选择题(每题2分,共40分)1. 编辑程序的功能是( )。
A.修改并建立源程序B.将源程序翻译成目标程序C.调试程序D.命令计算机执行指定的程序2. 以下不是c语言规定保留字的是( )。
A. floatB. integerC. signedD. unsigned3. 下面四个选项中,均是合法浮点数的选项是( )。
A. +1e+1 5e-9.4 03e2B. -e3 12e-4 -8e5C. 123e 1.2e-.4 +2e-1D. -.60 .8e-4 5.e-04. 设int a=2,b;则执行b=a&&1;语句后,b的结果是( )。
A.0B.1C.2D.35. 已知:int n, i=1,j=2;执行语句n=i<j?i++:j++;则n, i和j的值是( )。
A. 1,1,3B. 2,2,2C.1,2,2D. 2,1,36. 在C程序中,设一表达式中包含有int,long, unsigned和char类型的变量和数据,则表达式最后的运算结果类型是( )。
A.intB.charC.unsignedD.long7. 假定a和b为int型变量,则执行下述语句组后,b的值为( )。
a=1;b=10;do{b-=a;a++;} while (b--<0);A. -1B. -2C.8D.98. 语句while(!e);中,条件!e等价于( )。
A. e=0B. e!=0C. e!=1D. e=19. 函数调用时,下列说法中不正确的是( )。
A.若用值传递方式,则形式参数不予分配内存B.实际参数和形式参数可以同名C.主调函数和被调用函数可以不在同一个文件中D.函数间传送数据可以使用外部全局变量10. 两次运行下面程序,如果从键盘上分别输入6和4,则程序的输出结果是( )。
main ( ){int x;scanf(″%d″,&x);if(x++>5) printf(″%d″,x);else printf(″%d\n″,x-1);}A.7和5B.6和3C.7和4D.6和411. 设有函数调用语句“f(x1,x1+x2,(x1,x2));”,正确的说法是( )。
C语言程序设计期末考试试题含答案一、选择题(每题 2 分,共 40 分)1、以下选项中,不是 C 语言关键字的是()A intB floatC charD string答案:D解释:string 不是 C 语言的关键字,C 语言中表示字符串通常使用字符数组。
2、以下能正确表示八进制整数的是()A 0o123B 0123C 0x123D 123答案:B解释:在 C 语言中,八进制整数以数字 0 开头,所以 0123 是八进制整数。
3、以下变量定义中,合法的是()A int a=b=1;B char a='\0';C float 2a;D double a&;答案:B解释:A 选项中不能连续赋值;C 选项变量名不能以数字开头;D 选项变量名不能包含特殊字符&。
4、若有定义:int a=5, b=2; 则表达式 a/b 的值是()A 25B 2C 20D 3答案:B解释:C 语言中,两个整数相除结果为整数,舍去小数部分。
5、若有定义:int a5 ={1, 2, 3, 4, 5};则 a2的值是()A 2B 3C 4D 5答案:B解释:数组下标从 0 开始,所以 a2对应的值是 3 。
6、以下关于函数的叙述中,正确的是()A 函数可以嵌套定义B 函数可以嵌套调用C 函数可以没有返回值D 以上都不对答案:C解释:函数不能嵌套定义,但可以嵌套调用。
函数可以没有返回值,此时函数类型为 void 。
7、若有以下函数定义:```cint fun(int a, int b){return a + b;}```则调用 fun(1, 2)的返回值是()A 1B 2C 3D 4答案:C解释:函数 fun 实现了两个整数的相加,所以 fun(1, 2)的返回值是3 。
8、以下关于指针的叙述中,错误的是()A 指针可以指向变量B 指针可以指向数组C 指针可以指向函数D 指针不可以进行加减运算答案:D解释:指针可以进行加减运算,但运算的结果要根据指针所指向的数据类型来确定。
北京交通大学2008 ―2009 学年第二学期期末考试试题课程名称: C语言程序设计出题教师: __课程组___ 专业:_________ 班级:____________ 姓名:____________ 学号:_____________------------------------------------------------------------- 答题说明:要求所有解答均写在答题卡上,否则无效。
一、选择题(每题1分,共20分)1.设整型变量a为7,使b不为3的表达式是()。
A.b=a/2 B.b=9-(- -a)C.b=a%2 D.b=a>3?3:12.设int x=1,y=1;表达式(!x++ || y--)的值是( )。
A.0 B.1 C.2 D.-13.设变量定义为 int a[3]={1,4,7},*p=&a[2], 则*p的值是()。
A.&a[2] B.7 C.4 D.14.C语言中以追加方式打开一个文件应选择()参数。
A.“r”B.”w”C.“rb”D.“a”5.从循环体内某一层跳出,继续执行循环外的语句是:()。
A.break语句B.return语句C.continue语句D.空语句6.若变量c为char类型,能正确判断出c为数字的表达式是()。
A.‘0’<=c<=‘9’B.(c>=‘0’) || (c<=‘9’)C.(‘0’<=c) and (‘9’>=c)D.(c>=‘0’) && (c<=‘9’) 7.选出下列标识符中不是合法的标识符的是()。
A.hot_do B.cat1 C._pri D.2ab8.以下说法中正确的是()。
A.C语言程序总是从第一个的函数开始执行B.在C语言程序中,要调用的函数必须在main()函数中定义C.C语言程序总是从main()函数开始执行D.C语言程序中的main()函数必须放在程序的开始部分9.若有int a[10] , *p ; p=a ;,则()是对数组元素的正确的引用。
班号 学号 姓名 成绩《 计算机控制系统 》期末考试卷注意事项:1)接听手机发送短信等视同作弊 2)计算题不能只给结果,要有过程题目:一、填空 ……………………………………………………………( 30 分)1.(4分)计算机控制系统主要是在 和 上将连续系统离散的,影响系统的主要因素是 和 。
2.(2分)离散系统频率特性的主要特点是 。
3.(6分)计算机控制系统中, , , , ,可能产生量化,一个量化单位是 。
4.(3分)零阶保持器对系统频率特性有什么影响 ,在 , 时不可忽略。
5.(2分)离散系统由于量化产生的极限环振荡与系统传递函数的 有关;产生的不灵敏区与系统传递函数的 有关。
6.(4分)量化的非线性效应是由 引起的,形成的本质是由于 。
7.(2分)被控对象离散化应当采用 变换,在离散域实现连续控制律一般应当采用 变换。
8.(3分)选择计算机控制的动态范围时,应当考虑 和 ,满足 的条件。
9.(2分)连续系统可控可观,采样系统仍然可控可观的条件是 。
10.(2分)在计算机中实现时,P z z a z a n n n ()=+++-11 中哪个系数变化使根偏移量最大 ,特征根靠得太近会产生什么问题 。
二、作图题 …………………………………………………………… ( 10 分)2.1(5分)试画出图1Z 平面上两对极点各自对应的脉冲响应序列的大致形状。
图1 图22.2(5分)连续信号幅频|F(jw)|如下图所示,试画出它的采样信号的幅频谱 |F *(jw)|,(不考虑相位)。
图中,w1 = 6 rad/s, w2 = 8 rad/s, 采样频率 ws = 10 rad/s .三、计算题 …………………………………………………………… ( 30 分)3.1(15分)考虑图3所示系统,采样周期T =0.5秒。
求:(1)系统闭环传递函数W (z )=C(z)/R(z).(2)K 为何值时系统稳定?(3)K =2时系统的位置误差,速度误差 图33.2(15分)已知离散系统状态方程如下:求:(1)系统是否可控?是否可观?(2)取状态反馈u(k)=-Kx(k)+r(k),求常值反馈阵K ,使闭环极点为 z 1,2 = 0 。
2022年北京航空航天大学公共课《C语言》科目期末试卷A(有答案)一、填空题1、请读程序段:int a=1,b=2;if(a&b)printf("***\n");else printf("$$ $\n");以上程序段的输出结果是_______。
2、在C语言源程序中,一个变量代表【】。
3、C语言的源程序必须通过【】和【】后,才能被计算机执行。
4、若x和n均是int型变量,且x和n的初值均为5,则执行表达式x+=n++后x的值为_______,n的值为_______。
5、若有定义语句:int x=3,y=2;float a=2.5,b=3.5;则表达式(x+y)%2+(int)a/(int)b的值为_______。
6、函数process是一个可对两个整型数a和b进行计算的通用函数;函数max()可求这两个数中的较大者,函数min()可求它们中的较小者。
已有调用语句process(a,b,max);和process(a,b,min);。
请填空。
void process(_______){int result;result=(*fun)(x,y);printf("%d\n",result);}7、下面程序段是找出整数的所有因子。
请填空。
scanf("%d",&x);i=1;for(;_______;){if(x%i==0)printf("%3d",i);i++;}8、设有如下结构体说明:struct ST{int a;float b;struct ST*c;doublex[3];}st1;请填空,完成以下对数组s的定义,使其每个元素均为上述结构体类型。
_______9、假设变量a、b和c均为整型,以下语句借助中间变量t把a、b和c中的值进行交换,即把b中的值给a,把c中的值给b,把a中的值给c。
北航《C语言程序设计》答案```plaintext一、基本概念和语法1. 在C语言中,什么是标识符?答:标识符是由字母、数字和下划线组成的字符序列,用于给变量、函数等命名。
2. C语言的注释有哪几种形式?答:C语言的注释有单行注释(//)和多行注释(/* */)两种形式。
3. 请简要解释一下C语言中的变量声明和定义的区别。
答:变量声明是为变量分配内存空间,告诉编译器该变量的类型和名称;变量定义是在声明的基础上为变量分配初值。
4. C语言中有哪些基本数据类型?请列举并简要介绍。
答:C语言中有int、float、char、double、void等基本数据类型。
- int类型用于表示整数;- float和double类型用于表示浮点数;- char类型用于表示字符;- void类型用于表示无类型。
5. C语言中的运算符有哪些种类?请简要介绍一下算术运算符和逻辑运算符。
答:C语言中的运算符包括算术运算符、关系运算符、逻辑运算符等。
- 算术运算符用于完成基本的算术运算,如加法(+)、减法(-)、乘法(*)、除法(/)等;- 逻辑运算符用于处理逻辑判断,如与(&&)、或(||)、非(!)等。
二、流程控制语句1. C语言中的条件语句有哪些?请简要介绍if语句和switch语句。
答:C语言中的条件语句有if语句和switch语句。
- if语句用于判断条件是否成立,若条件为真,则执行相应的代码;- switch语句用于根据表达式的值选择执行不同的代码块。
2. 循环语句在C语言中有哪几种形式?请简要介绍while循环和for循环。
答:C语言中的循环语句有while循环、do-while循环和for循环。
- while循环用于在指定条件为真的情况下重复执行一段代码;- for循环结构更加灵活,通过初始化、条件和增量表达式来控制循环次数。
三、函数和数组1. C语言中的函数有哪些特点?请简要介绍函数的定义和调用。
一、选择题1、下列数据中,为字符串常量的是<).A、'A'B、How do you do.C、$abcD、"house"2、以下所列的C语言常量中,错误的是( >.A、0xFFB、1.2e0.5C、2LD、'\72'3、以下程序的输出结果是<). main(>{float x=3.6。
int i。
i=(int>x。
printf("x=%f,i=%d\n",x,i>。
}A、x=3.600000,i=4B、x=3 i=3.600000C、x=3,i=3D、x=3.600000,i=34、若k是整型,则以下程序段的执行结果是:( >k=-3。
if(k<=0> printf("####">else printf("&&&&">。
A、####B、有语法错误,无结果C、&&&&D、####&&&&5、若x=2,y=3则x||y的结果是( >.A、3B、0C、1D、26、针对下列程序段回答问题( >. for(t=1。
t<=100。
t++>{scanf("%d",&x>。
if(x<0> continue。
printf("%3d",t>。
}A、x>=0时什么也不输出B、最多允许输出100个非负整数C、printf函数永远也不执行D、当x<0时整个循环结束7、以下程序的执行结果是( >. main(>{ int num = 0。
while( num <= 2 >{ num++。
printf( "%d,",num >。
2007-2008C语言程序设计期末试卷第一部分:客观题一、单项选择题(共30题,1分/题,共30分)下列各题A、B、C、D 四个选项中,只有一个选项是正确的,请将正确选项涂在机读卡相应位置上,答在试卷上不得分。
1、C语言源程序构成的基本单位是(B)。
A.文件B.函数C.过程D.主函数2、下列哪个选项是C语言提供的合法保留字(A)。
A.mainB.IntC.cherD.max3、下列常量表示中哪个选项不符合C语言的规定(D)。
A.1LB.0123C.12e-2D. 'ab'4、执行下面程序段后,变量y的数据类型是(B)。
int x;float y=9.6; x=(int)y+ 'a';A.intB.floatC.charD.不确定5、语句a=(a=9,a+10,a*2);运行后,变量a的值是(B)。
A.9B.18C.19D. 386、执行下面程序段后,变量a,b,c的值分别是(D)。
int a,b,c; a=b=0; c=(++a<=0)&&(b=1)A.1,1,1B.1,0,1C.1,1,0D.1,0,07、设有定义int a=2;,执行语句a+=a-=a*=a;后,变量a的值是(A)。
A.0B.4C.8D.-48、设有定义int n=010,i=3;,执行语句n%=i+1;后,变量n的值是(A)。
A.0B.1C.2D.39、设有定义:int k=0;,以下选项的四个表达式中与其他三个表达式的值不相同的是(B)。
A.k++B.k+=1C.++kD.k+110、执行下面程序段后,变量k的值是(B)。
int k,m=1,n=2;if(m>n) k=m>n;else k=m<=n;A.0B.1C.m<=nD.赋值语句有错,编译不能通过11、若下列选项中的标识符已经定义,则正确的赋值表达式是(C)。
A.x1=25.5%2B.a=b+3+=1C.x=f(x)+3D.f(x)=f(x-1)+f(x-2)12、下面程序段的输出结果是(B)。
北京航空航天大学数据结构与C语言程序设计2005-2008、2010-2012年(12年带
答案)
Tao:彩虹真题(考研考博)出售真题价格如下:
所有真题价格如下:
2000年之前真题试卷均可免费赠送(前提:购买其它年份真题,如此校只有1999-2000年,均为2元每年每份。
)
2001-2008年真题试卷均为1元每年每份
2009-2011年真题试卷均为2元每年每份
2012年真题试卷均为5元每年每份(若有)
2013年真题试卷均为10元每年每份(若有)
注:回忆版本价格从优,个别比较难得的专业课真题价格再定,如有附带答案的可免费附赠,个别特殊答案价格再定(会标注)。
恭祝大家考试成功,金榜题名!。
一、阅读下列程序并回答问题(20分,每题5分)
1、若有以下程序
#include <stdio.h>
void main()
{
char a[20];
scanf(“%s”,a);
printf(“%s\n”,a);
}
从键盘上输入19个字符:one world one dream, 则输出为。
A. one world one dream
B. one world one
C. one world
D. one
2、有一函数关系如下:
x-1 x<0
y= x x=0
x+1 x>0
下列程序能够正确表示上述关系的是__________________________。
A. y=x+1;
B. y=x-1;
if (x>=0) if (x!=0)
if (x==0) y=x; if (x>0) y=x+1;
else y=x-1; else y=x;
C. if (x<=0)
D. y=x;
if (x<0) y=x-1; if (x<=0)
else y=x; if (x<0) y=x-1;
else y=x+1; else y=x+1;
3、请写出以下程序的输出结果:______________________________。
#include <stdio.h>
void swap(int *ptr1,int *ptr2)
{
int i;
i=*ptr1;
*ptr=*ptr2;
*ptr2=i;
}
void exchange(int *q1,int *q2,int *q3)
{
if (*q1<*q2) swap(q1,q2);
if (*q1<*q3) swap(q1,q3);
if (*q2<*q3) swap(q2,q3);
}
void main()
{
int a,b,c;
a=9,b=3,c=12;
exchange(&a,&b,&c);
printf(“a=%d,b=%d,c=%d\n”,a,b,c);
}
4、若有以下程序
#include <stdio.h>
int sum(int k);
void main()
{
int s,i;
for (i=1;i<=10;i++) s=sum(i);
printf(“s=%d\n”,s);
}
int sum(int k)
{
static int x=0;
x+=k;
return (x);
}
(1)上述程序的功能是什么?运行结果是什么?
(2)若将sum()函数中的变量说明语句static int x=0;改为int x=0;,程序的运行结果是又什么?为什么?
二、程序填空题(20分,每题5分)
1、下面程序是整元换零钱问题。
把1元兑换成1角、2角和5角的零钱,打印所有的不同的换法。
#include <stdio.h>
void main()
{
int x,y,z,n;
____________ ;
for (x=0;x<=10;x++)
for (y=0;y<=5;y++)
for (z=0;z<=2;z++)
if ( _________________________ )
{
n++;
printf("换法%2d: 1角%2d张+2角%d张+5角%d张
\n",n,x,y,z);
}
}
2、以下函数利用插入排序方法对含有n个元素的数组x[]进行排序。
void insert(int x[],int n)
{
int i,j;
int temp;
for (i=1;i<n;i++)
{
temp=x[i];
j=i-1;
while (j>=0 && temp<x[j])
{
;
j--;
}
x[j+1]= ;
}
}
3、下面程序显示从3起小于100的所有双素数(双素数:如果p和q都是素数且q=p+2,则p/q称为双素数,例如3/5,5/7都是双素数)。
#include "stdio.h"
int prime(int m);
int main(int argc, char* argv[])
{
int p,q;
for (p=3;p<100;p+=2)
{
q = ;
if ( prime(p) && prime(q) ) printf("%d/%d\n",p,q);
}
return 0;
}
int prime(int m)
{
int i;
for ( i = 2; ; i++ )
if ( m % i == 0 ) ;
if ( i > m/2 ) return 1;
else return 0;
}
4、下面的函数strcat()实现将字符串str2连接到字符串str1的功能。
请在程序的空白处填入一条语句或一个表达式。
char *strcat(char *str1,char *str2)
{
char *t=str1;
while ( ) str1++;
while ( *str2 )
{
;
str1++;
str2++;
}
*str1= ;
return (t);
}
三、编程题(60分)
1、输入一个正整数n (1<n≤6),根据下式生成1个n*n的方阵,然后将该方阵转置(行列互换)后输出。
10分a[i][j] = i * n + j + 1(0≤i≤n-1,0≤j≤n-1)
例如n=3时:
1 2 3 1 4 7
A= 4 5 6 转置成B= 2 5 8
7 8 9 3 6 9
2、请设计函数double exp(double x),利用e x=1+x+x2/2!+x3/3!+x4/4!+…,计算e x的近似值,要求误差小于10-6。
20分
3、Fibonacci数列A={1,1,2,3,5,8,…}有如下性质:30分
a0=a1=1
a i=a i-1+a i-2 i>1
对于给定的n,另外有一个由n个元素组成的数列X={x0,x1,…,x n},该数列中各元素的值为:x i=a i/a i+1i=0,1,2,…,n,请将X中的元素按由小到大排序,排序用选择法或冒泡法,排序后的数列X输出到文本文件x.txt中,X中的各元素仍以分数形式表示。
例如,当n=5时,排序前的X={1/1,1/2,2/3,3/5,5/8},排序后的X={1/2,3/5,5/8,2/3,1/1}。