最新 年电大C语言程序设计课程期末复习考试题库小抄(c语言小题+编程).doc
最新电大C语言程序设计课程期末复习考试题库小抄 一、单项选择题 1在每个C语言程序中都必须包含有这样一个函数,该函数的函数名为( )。 A. main B. MAIN C. name D. function 2每个C语言程序文件的编译错误分为 类。 A. 1 B. 2 C. 3 D. 4 3. 字符串"a+b=12n"的长度为 。 A. 6 B. 7 C. 8 D. 9 4. 在switch语句的每个case块中,假定都是以break语句结束的,那么此switch语句容易被改写为 语句。 A. for B. if C. do D. while 5. 在下面的do-while循环语句中,其循环体语句被执行的次数为 。 int i=0; do i+; while(i<10); A. 4 B. 3 C. 5 D. 10 6. 将两个字符串连接起来组成一个字符串时,选用的函数为 。 A. strlen() B. strcap() C. strcat() D. strcmp() 7. 假设用数组名作为函数调用的实参,传递给形参的是 。 A. 数组的首地址 B. 数组中第一个元素的值 C. 数组中全部元素的值 D. 数组元素的个数 8. 假定a为一个整数类型的数组名,整数类型的长度为4,那么元素a4的地址比a数组的首地址大( )个字节。 A. 4 B. 8 C. 16 D. 32 9. 假定s被定义为指针类型char *的变量,初始指向的字符串为"Hello world!",假设要使变量p指向s所指向的字符串,那么p应定义为 。 A. char *p=s; B. char *p=&s; C. char *p;p=*s; D. char *p; p=&s; 10. 从一个数据文件中读入以换行符结束的一行字符串的函数为 。 A. gets() B. fgets() C. getc() D. fgetc() 11. 由C语言目标文件连接而成的可执行文件的缺省扩展名为( )。 A. cpp B. exe C. obj D. c 12. 设有两条语句为“int a=12; a+=a*a;,那么执行结束后,a的值为( )。 A. 12 B. 144 C. 156 D. 288 13. 带有随机函数调用的表达式rand()%20的值在( )区间内。 A. 119 B. 120 C. 019 D. 020 14. for循环语句“for(i=0; i<n; i+=2) S;中循环体S语句被执行的次数为 。 A. (n+1)/2 B. n/2+1 C. n/2-1 D. n-1 15. 在以下的字符数组定义中,存在语法错误的选项是 。 A. char a20="abcdefg" B. char a="x+y=55." C. char a15='1','2' D. char a10='5' 16. 假设有一个函数原型为“double *function(),那么它的返回值类型为 。 A. 实数型 B. 实数指针型 C. 函数指针型 D. 数组型 17. 在C语言中,所有预处理命令都是以( )符号开头的。 A. * B. # C. & D. 18. 假定整数指针p所指数据单元的值为30,p+1所指数据单元的值为40,那么执行*p+后,p所指数据单元的值为 。 A. 40 B. 30 C. 70 D. 10 19. 假设要使p指向二维整型数组a1020,那么p的类型为 。 A. int * B. int * C. int *20 D. int(*)20 20. 表示文件结束符的符号常量为 A. eof B. Eof C. EOF D. feof 21. 程序运行中需要从键盘上输入多于一个数据时,各数据之间默认使用( )符号作为分隔符。 A. 空格或逗号 B. 逗号或回车 C. 逗号或分号 D. 空格或回车 22. 逻辑表达式(x>0 && x<=10)的相反表达式为 。A. x<=0 | x>10 B. x<=0 && x>10C. x<=0 | x<=10 D. x>0 && x>10 23. 当处理特定问题时的循环次数时,通常采用 循环来解决。 A. for B. while C. do-while D. switch 24. 假定i的初值为0,那么在循环语句“while(i<n) s+=i*i; i+;中循环体被执行的总次数为 。 A. n-1 B. n C. n+1 D. n/2 25. 假定一个二维数组的定义语句为“int a34=3,4,2,8,6;,那么元素a12的值为 。 A. 2 B. 4 C. 6 D. 8 26. 在以下选项中,不正确的函数原型格式为 。 A. int Function(int a); B.void Function (char); C. int Function(a); D.void int(double* a); 27. 假定p是一个指向float型数据的指针,那么p+1所指数据的地址比p所指数据的地址大( )个字节。 A. 1 B. 2 C. 4 D. 8 28. 假定有定义为“int m=7, *p;,那么给p赋值的正确表达式为 。 A. p=m B. p=&m C. *p=&m D. p=*m 29. 假定指针变量p定义为“int *p=malloc(sizeof(int);,要释放p所指向的动态存储空间,应调用的函数为 。 A. free(p) B. delete(p) C. free(*p) D. free(&p) 30. C语言中的系统函数fopen()是 一个数据文件的函数。 A. 读取 B. 写入 C. 关闭 D. 翻开参考解答: 1. A 2. B 3. B 4. B 5. D 6. C 7. A 8. C 9. A 10. B 11. B 12. C 13. C 14. A 15. D 16. B 17. B 18. A 19. D 20. C 21. D 22. A 23. A 24. B 25. C 26. C 27. C 28. B 29. A 30. D 二、填空题 1C语言中的每条简单语句以_;或分号作为结束符。 2. C程序中的所有预处理命令均以_#_字符开头。 3. 当不需要函数返回任何值时,那么应使用void 标识符来定义函数类型。 4十进制数25表示成符合C语言规那么的十六进制数为0x19 5. 假定不允许使用逻辑非操作符,那么逻辑表达式a>b | b=5的相反表达式为a<=b && b!=5 6. 执行“typedef int DataType;语句后,在使用int定义整型变量的地方也可以使用_ DataType _来定义整型变量。 7. 假定一维数组的定义为“char* a8;,那么该数组所占存储空间的字节数为_32 _。 8. 假定二维数组的定义为“double aMN;,那么该数组的列下标的取值范围在_0N-1_之间。 9. 存储一个空字符串需要占用_1 _个字节。 10. strcpy函数用于把一个字符串_拷贝复制_到另一个字符数组空间中。 11. 程序的编译单位是一个_程序文件 _。 12. 假定a是一个一维数组,那么ai的指针访问方式为_*(a+i)_。 13. 执行int *p=malloc(sizeof(int)操作得到的一个动态分配的整型对象为_*p _。 14执行“printf("%c",'A'+2);语句后得到的输出结果为_ C _。 15short int类型的长度为_2 _。 16. 用类型关键字表示十进制常数的类型为_ float _。 17. 假定y=10,那么表达式+y*3的值为_ 33_。 18. 逻辑表达式(x=0 && y>5)的相反表达式为_(x!=0 | y<=5) 或:(x | y<=5) _。 19假设x=5,y=10,那么x!=y的逻辑值为_1_。 20. 假定二维数组的定义为“int a35;,那么该数组所占存储空间的字节数为_60 _。 21. 使用“typedef char BB1050;语句定义_ BB _为含有10行50列的二维字符数组类型。 22. 字符串"a:xxk数据"的长度为_11_。 23假定p所指对象的值为25,p+1所指对象的值为46,那么*+p的值为_46 _。 24. 假定一个数据对象为int*类型,那么指向该对象的指针类型为_ int* _。 25假定一个结构类型的定义为 “struct Aint a,b; A* c;,那么该类型的长度为_12 _。 26. 假定要访问一个结构对象x中的数据成员a,那么表示方式为_ _。 27. 用于输出表达式值的标准输出函数的函数名是_ printf _。 28每个C语言程序文件在编译时可能出现有致命性错误,其对应的标识符为_ error _。 29. 'A''Z'的ASCII码为6590,当执行“int x='C'+3;语句后x的值为_70_。14_。 31. 假定不允许使用逻辑非操作符,那么关系表达式x+y>5的相反表达式为_ x+y<=5 32. 假定x=5,那么执行“a=(x?10:20);语句后a的值为_10 _。 33. 假定一维数组的定义为“char* aM;,那么该数组所占存储空间的字节数为_4*M _。 34. 存储字符串"a"需要至少占用存储器的_2_个字节。 35. strlen()函数用于计算一个字符串的_长度_。 36. 在C语言中,一个函数由函数头和_函数体_这两个局部组成。 37假定p所指对象的值为25,p+1所指对象的值为46,那么执行表达式*(p+)后,p所指对象的值为_46_。 38. 假定p是一个指向整数对象的指针,那么用_&p _表示指针变量p的地址。 39. 与结构成员访问表达式p->name等价的访问表达式为_(*p).name _。参考解答:1. ;或分号 2. # 3. void 4. 0x195. a<=b && b!=5 6. DataType 7. 32 8. 0N-19. 1 10. 拷贝复制 11. 程序文件 12. *(a+i)13. *p 14. C 15. 2 16. float17. 33 18. (x!=0 | y<=5) 或:(x | y<=5) 19. 1 20. 60 21. BB 22. 1127. printf 28. error 29. 70 30. 1431. x+y<=5 32. 10 33. 4*M 34. 235. 长度 360. 函数体 37. 46 38. &p39. (*p).name五、按题目要求编写程序或函数 1. 编写一个程序,输出50以内含50的、能够被3或者5整除的所有整数。#include<stdio.h> void main() int i; for(i=3; i<=50; i+) if(i%3=0 | i%5=0) printf("%d ",i); printf("n"); 2. 编写一个递归函数“int FF(int a, int n),求出数组a中所有n个元素之积并返回。int FF(int a, int n) if(n<=0) printf("n值非法n"),exit(1); if(n=1) return an-1; else return an-1*FF(a,n-1); 3. 编写一个程序,利用while循环,计算并打印输出的值,其中正整数n值由键盘输入。假定求和变量用sum表示,计数变量用i表示,sum、i和n均定义为全局变量,sum和i的初值分别被赋予0和1。#include<stdio.h> int n,i=1; double sum=0; void main() scanf("%d",&n); while(i<=n) sum+=(double)1/i+; printf("sum=%lfn",sum); 4. 根据函数原型“void DD(int a, int n, int MM)编写函数定义,利用双重循环查找并打印输出数组an中任何两个元素的值等于MM值的元素值。假定ai+aj等于MM,那么输出格式为:(ai,aj)。void DD(int a, int n, int MM) int i,j; for(i=0; i<n; i+) for(j=i+1; j<n; j+) if(ai+aj=MM) printf("%d, %dn", ai,aj); 5. 编写一个程序,计算1+3+32+.+310的值并输出,假定分别用i,p,s作为循环变量、累乘变量和累加变量的标识符。#include<stdio.h> void main() int i; int p=1; int s=1; for(i=1;i<=10;i+) p*=3; s+=p; printf("%dn",s); 6. 根据函数原型“int FF(int a, int n),编写函数定义,计算并返回数组an中所有元素之和。int FF(int a, int n) int i,sum=0; for(i=0; i<n; i+) sum+=ai; return sum; 7. 根据函数原型“double Mean(double aMN,int m,int n),编写函数定义,要求返回二维数组amn中所有元素的平均值。假定在计算过程中采用变量v存放累加值和最后的平均值。double Mean(double aMN,int m,int n) int i,j; double v=0.0; for(i=0; i<m; i+) for(j=0; j<n; j+) v+=aij; v/=m*n; return v; 注:函数体的最后两行可以合并为一条返回语句:return v/=m*n 8. 根据函数原型“int MM(int a,int m),编写函数定义,计算并返回数组am中元素最大值和最小值之差。int MM(int a,int m) int i,x1,x2; x1=x2=a0; for(i=1; i<m; i+) if(ai>x1) x1=ai; if(ai<x2) x2=ai; return x1-x2; Visa-free policy brings Chengdu biz, tourism boost. Making national headlines several times, Chengdu's 72-hour visa-free policy has attracted wide attention from both Chinese and foreign experts and businessmen since it took effect on Sept 1 last year. The program permits citizens from 51 countries and regions including the United States, Australia, Canada and Japan who have valid visas and flight tickets to a third country to spend three days in the city. The capital of Sichuan province is the first city in the western region of China to offer foreign tourists a three-day visa and the fourth nationwide to adopt the policy following Shanghai, Beijing and Guangzhou. Li Zhiyong, deputy dean of the tourism institute at Sichuan University, said the move "contributes to a large increase in the number of overseas tourists and raises the city's level of internationalization". "The policy will also bring direct economic revenue," Li said. "Chengdu has many cultural legacies and is also a paradise for panda lovers with the world's largest breeding and research center. Three days are long enough for foreign visitors to visit those iconic tourist spots," he noted. The city is home to the remains of the Jin sha civilization that dates back more than 3,000 years as well as the Qing cheng Mountains and the Du jiang yan irrigation system. Qing cheng has long been recognized as the birthplace of Taoism, China's ancient indigenous religion, while Du jiang yan is considered to be the oldest functioning water-control project in the world. Chengdu ranked third in tourist facilities, management and services among 60 Chinese cities in a customer satisfaction survey released last year. But, Li added that efforts are still needed to develop more tourism products, improve English services and provide accurate translation of traffic signs and scenic billboards. Zhao Yun, chairwoman of British Chamber of Commerce Southwest China, told China Daily that his colleagues found the policy very convenient. "A British client once flew here and stayed for just one day to check her ordered goods," she said. Zhao was born in Shanxi province, but she has lived in Chengdu for more than 10 years. "My life was like a running race moving from place to place. I also lived in Beijing and Shanghai before," she said. "But Chengdu is a place that you never want to leave once settling down. It is now my second hometown," she said. If the environment is further improved, the city will attract more people to visit and live, with the 72-hour visa-free policy and compelling conditions in transportation, culture, climate and cuisine, he said. Foreigners also gave positive feedback on the policy. A spokesman from Dell Inc said the company has a global hub of operation in Chengdu, so the three-day visa "has an immediate and positive influence on the company's business development". Rudy Buttignol, president of the public broadcasting company in British Columbia, Canada, said his work requires frequent travel to Chengdu and the policy "makes the trips easier". Data from the city's public security bureau shows some 100 foreign visitors enjoyed the 72-hour policy by the end of March, most of them from the United States, the United Kingdom and Germany. Chengdu also reported robust growth in its overall tourist industry last year. Official statistics show that it received some 150 million tourists last year, an increase of 28 percent from 2021. Around 1.7 million came from abroad, an increase of 12 percent. Total revenue from tourism surpassed 133 billion yuan ($21.7billion). During his visit to Kazakhstan in September, Chinese President Xi Jinping proposed that China and Central Asia join hands to build a Silk Road economic belt to boost cooperation. The idea has been widely echoed in Central Asian countries, becoming an encouraging blueprint for Chinese areas along the Silk Road that has linked Asia and Europe for more than 2,000 years. In the next three weeks, China Daily reporters will travel through the belt in China and in Kazakhstan, Uzbekistan and Turkey. They will show the progress and expectations of the countries, businesses and peoples on the route. Shaanxi - the start of the ancient Silk Road - has positioned itself as the new starting point for the development of the Silk Road Economic Belt, which will strengthen China's cooperation with Central Asian countries, a senior official said. Shaanxi Governor Lou Qinjian said the province is fresh, rich and unique, as it was when it anchored one end of the ancient Silk Road. "It is the best option for accommodating industrial transfers from East China or the world at large," he said on Wednesday in Xi'an.Lou held a joint interview with 27 media, including China Daily, the first in a series of interviews entitled Chinese Media Along the Silk Road. The interviews will be in Shaanxi and Gansu provinces and the Xinjiang Uygur autonomous region, as well as Kazakhstan, Uzbekistan and Turkey. The media group held the first interview on Wednesday morning in Xi'an, the starting point of the ancient Silk Road, a trade channel established more than 2,000 years ago linking China, Central Asia and Europe.内部资料,请勿外传!9JWKffwvG#tYM*Jg&6a*CZ7H$dq8KqqfHVZFedswSyXTy#&QA9wkxFyeQ!djs#XuyUP2kNXpRWXmA&UE9aQGn8xp$R#͑GxGjqv$UE9wEwZ#QcUE%&qYpEh5pDx2zVkum&gTXRm6X4NGpP$vSTT#&ksv*3tnGK8!z89AmYWpazadNu#KN&MuWFA5uxY7JnD6YWRrWwcvR9CpbK!zn%Mz849GxGjqv$UE9wEwZ#QcUE%&qYpEh5pDx2zVkum&gTXRm6X4NGpP$vSTT#&ksv*3tnGK8!z89AmYWpazadNu#KN&MuWFA5uxGjqv$UE9wEwZ#QcUE%&qYpEh5pDx2zVkum&gTXRm6X4NGpP$vSTT#&ksv*3tnGK8!z89AmYWpazadNu#KN&MuWFA5uxY7JnD6YWRrWwcvR9CpbK!zn%Mz849GxGjqv$UE9wEwZ#QcUE%&qYpEh5pDx2zVkum&gTXRm6X4NGpP$vSTT#&ksv*3tnGK8!z89AmUE9aQGn8xp$R#͑GxGjqv$UE9wEwZ#QcUE%&qYpEh5pDx2zVkum&gTXRm6X4NGpP$vSTT#&ksv*3tnGK8!z89AmYWpazadNu#KN&MuWFA5uxY7JnD6YWRrWwcvR9CpbK!zn%Mz849GxGjqv$UE9wEwZ#QcUE%&qYpEh5pDx2zVkum&gTXRm6X4NGpP$vSTT#&ksv*3tnGK8!z89AmYWpazadNu#KN&MuWFA5uxGjqv$UE9wEwZ#QcUE%&qYpEh5pDx2zVkum&gTXRm6X4NGpP$vSTT#&ksv*3tnGK8!z89AmYWpazadNu#KN&MuWFA5uxY7JnD6YWRrWwcvR9CpbK!zn%Mz849GxGjqv$UE9wEwZ#QcUE%&qYpEh5pDx2zVkum&gTXRm6X4NGpP$vSTT#&ksv*3tnGK8!z8vG#tYM*Jg&