C语言考试题及答案[1]_第1页
C语言考试题及答案[1]_第2页
C语言考试题及答案[1]_第3页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、C语言考试题及答案1I. in dividual choice questio ns: (10 poin ts, 2 points per subject)1. char *p10; this statement declares one: C.A) pointer variable p to a one-dimensional character array containing10 eleme ntsB) pointer variable p that points to a string of no more than 10C) a pointer array P with 10 ele

2、ments, each of which can point to a stri ngD) a pointer array P with 10 elements, each of which holds a string2. if int x: and with the following program fragment, the output is:D.For (x=3: x<6: x+)n”, X”);Printf (x%2),(A) #3 B) *3 C) *3 D) #3*4 *4 #4 #4*5 #5#5 *53. in the while () x stateme nt,

3、X ' is equivale nt to the followi ng con diti onal expressi on: D.A) x, =0, B) x=l, C), x, =1, D) x=04. knownStruct pointInt x;Int y:;Struct rectStruct point ptl:Struct point pt2:;Struct rect rt:Struct, rect, *rp = &rt;Which of the followi ng refere nces is in correct, _D?.A) rt. ptl. x B) (

4、*rp).Ptl. xC) rp->ptl. x D) rt -ptl. x5. if the two-dimensional array a has m rows and N columns, then thefollowing element ai j can be correctly refereneed: C.(A) * (a+j* n+i) B * (a+i* n+j)C) * (* (a+i) +j) D * (*a+i) +jCDDDCTwoan alyze the procedure and write the running result, (25 poin ts,5

5、points per subject)Onefti nclude <stdio.h>(main)Int n;Static char *monthName="Illegal month ” , "January ” , "February" March , April , May, June , July , August ,"September” , "October ” , "November ” , "December"For (n-1: n<=12: n+)n”, monthNam

6、en);Operation results are:JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecemberTwo#include<stdio. h>ftdefine ARR_SIZE 7Void YH (int, a ARR_SIZE, int, n):Void PrintYH (int, a ARR_SIZE, int, n):(main)Int aARR_SIZEARR_SIZE:YH (a, ARR SIZE-1);PrintYH (a, ARR_SIZE-1);Void YH (i

7、nt, a ARR_SIZE, int, n)Int, I, j:For (i=l: i<-n; i+)For (j=l: j<=i: j+)If (j=l i=j I )Aij = 1;ElseAi j = ai-l j-1 + ai-l j: void printyh (int a arr _ size, int n)int i, j:for (i = 1; in < = n; i + +) for (j = 1; j < = i; j + +)printf ("% 4d ”, a i j);printf ( n ) ;运行结果是 :11 11 2 113

8、 3 11 4 6 4 11 5 10 10 5 13.# include stdio. h > <main ()int i, n;for (i = 1; in < = 5; i + +) printf ("please enter n:");scanf ("% d ”, & n);if (n = = 0) continue:printf (n =% d n ”, n);printf ("programme is over! n ");程序运行时输入: 1 2 3 4 5/运行结果是:n = 1please enter

9、 n: please enter n: n = 3please enter n: please enter n: n = 5 programme is over!# include stdio. h > < void func (int n);main () int i;for (i = 0; i < 2; i + +)func (in);void func (int n)static int t = 1;printf (t =% d "n" t + +);运行结果是:# include stdio. h > <int func (int i)

10、;main ()int i;for (i = 3; in < 5; i + +)printf ("% d”, func (in)printf (" n");int func (int i) static int c = 10: ( ; i > 0; i ) c + +;return (k);运行结果是:13 17三、阅读并完成程序,在标有下划线的空白处填入适当的表达式或语 句,使程序完整并符合题目要求 .(20 分,每空 2 分)1. 下面程序用于读入 10 个字符串,然后找出最大的字符串并打印# include stdio. h > <#

11、 include string, h > <main () char str 10 80, maxstring 80: printf ("enter tenstrings: n");for (i = 0; i < 10; i + +)scanf ("% s" str i);strcpy (maxstring, str 0);for (i = 1; in < 10; i + +)if (strcmp (maxstring, str i) < 0)0或 strcmp (str i, maxstring) >strcpy (

12、maxstring, str i);printf ("the max string is:%s" n ”, maxstring)2. 下面这个程序用于交换两个数组的对应元素的值# include stdio. h > <# define array _ size 10void swap (int * x, int * y);void exchange (int a , int b , int n):void inputarray (int a , int n):void printarray (int a , int n):main () int a array

13、 _ size, b array _ size, n;printf ( z/ input array lenth n < = 10:");scanf ("% d ”, & n);printf ( z/ input array a: n");inputarray (a, n);printf ( z,input array b: n");inputarray (b, n);exchange (a, b, n);(np"r"ai)nf;ttef r(z/ array a:tnh"e); swap: vpinortii

14、ndtasrwr ayp(ain, tn*);int *xte, mp:y)pterimntpf (= * z/ array b: n");x;*prxin=ta*rray (b, n);vyo; id exchange (int a , int b , int n) int i;for (i = 0; i < n; i + +) swap (& a i, & b i);void inputarray (int a , int n) int i;for (i = 0; i < n; i + +) scanf ("% d" & a

15、 i); void printarray (int a , int n) int i;for (i = 0; i < n; i + +)printf ("% d ”, a i) :printf (" n");3. 从键盘任意输入一个年号,判断它是否是闰年. 若是闰年,输出 yes, no. 已知符合下列条件之一者是闰年:否则输出能被 4 整除,但不能被 100整除 .能被 400 整除 .# include stdio. h > <int year, flag;printf ("enter year:");scanf (&qu

16、ot;% d ”, & year);if (a% 4 = = 0 & & year% 100! = 0 | | year% 400 = = 0)flag = 1:elseflag = 0:if (flag) printf ("yes! n ");else printf ("no! n ");四、在下面给出的 4个程序中,共有 15 处错误(包括语法错误和逻 辑错 误),请找出其中的错误,并改正之 . (在错误的代码下边画一 根横线, 把正确的代码写在旁边;漏掉的代码正确插入合适的位置.30 分,每找对1 个错误,加 1 分,每修改

17、正确 1 个错误,再加 1 分 . )1. 编程计算矩阵相乘之积 .# include stdio. h > <# define row 2 # define col 3 / / void multiplymatrix (int a row col, int b col row, int c row row);int a row col, b col row, c row row, i, j: printf ( z input array a: n");for (i = 0; i < row; i + +)for (j = 0, j < col; j + +)

18、scanf ("d" & a i j): / /% dprintf ( z,input array b: n");for (i = 0; i < col; i + +)for (j = 0, j < row; j + +) scanf ("d" & b in j); multiplymatrix (a, b, c).printf ("results: n");void multiplymatrixfor (i = 0; i < row; i + +) for (j = 0, j < r

19、ow; j + +) printf ("% 6d, " & c i j) ; / / c i j printf ( n );(int a row with, int b with row, int c row row) int i, j, k;for (i = 0; i < row; i + +)for (j = 0, j < row; j + +)for (k = 0; k < with; k + +)/ / c i j = 0.c i j = c i j + a i k b j k; / / b k j2. 编程输入 10 个数,找出其中的最大

20、值及其所在的数组下标位置# includes stdio.h > < int findmax (int num , int n, int * pmaxpos): main () int num 10, maxvalue, maxpos, minvalue, minpos, / /;printf ( z/ input 10 numbers: n");for (i = 0; i < 10; i + +)scanf ("% d ”, num ) : / / & num maxvalue = findmax (num, 10 * maxpos); / /

21、& maxposprintf (max =% d, position =% d n ”, maxvalue, maxpos);int findmax (int num , int n, int * pmaxpos)int i, max;max = num 0.for (i = 1, i < n, + + + + + + +) / / a=l; i < n;if (num > max) max = num ;pmaxpos = i;return max;3. 韩信点兵 . 韩信有一队兵,他想知道有多少人,便让士兵排队报数 : 按从 1至 5 报数,最末一个士兵报的数为

22、1;按从 1 至 6 报数,最末 一个士 兵报的数为 5; 按从 1 至 7 报数,最末一个士兵报的数为 4; 最后再按从 1 至 11 报数,最末一个士兵报的数为 10. 你知道韩信至 少有多少兵吗?# includes stdio. h > <main () int x; / / x = 0while (1) if (x% 5 = 1 & & x% 6 = 5 & & x% 7 = 4 & & x% 11 = 10)/x%5=l&&x%6=5&&x%7=4&&x%ll=10break

23、;x + + / x + +;printf (x =% d n ”, x);面函数 squeez () 的功能是删除字符串 s 中所出现的与变量 c 相同4.的字符.void squeeze (char s , char c) ; / / void squeeze (char s , char c) int i, j: / / j = 0;for (i = 0; s i. = ' O' ; i + +)if (s i. = c) / / cd j = s i.j + +?s i = ' 0' ; / / d j = ' 0,.或 / / d j = &#

24、39; 0,.五、编程 (15 分 )Enter a class 10 students from the keyboard arbitrarily, call the save function to the data stored in the disk file name to your number, and then open the file to read data, results from high to low ranking, the number of students failing and print. Finally, the save function is c

25、alled again to store the data into the original disk file. Programming is required according to the function prototype as shown below:Void save (float, score, int, n):Void Sort (float, score, int, n):Int Fail (float, score, int, n):Requires a one-dimensional array to do function parameter programmin

26、g, achievement sorting and statistical scores failed students, and then print the results in the main function, you can not use global variables programming.The reference procedure is as follows:Void load (float, score, int, n) /3 points(FILE *fp;Int i;If (fp=fopen (02406101, , Rb,) =NULL)(printf ( z/ cannot open infile'n");Return;For (i=0: i<n; i+)If (FREAD (&

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论