C語言考試題及答案[1]_第1頁
C語言考試題及答案[1]_第2頁
C語言考試題及答案[1]_第3頁
免費預覽已結(jié)束,剩余22頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

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 ) ;運行結(jié)果是 :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/運行結(jié)果是: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 + +);運行結(jié)果是:# 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);運行結(jié)果是:13 17三、閱讀并完成程序,在標有下劃線的空白處填入適當?shù)谋磉_式或語 句,使程序完整并符合題目要求 .(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. 下面這個程序用于交換兩個數(shù)組的對應元素的值# 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 個數(shù),找出其中的最大

20、值及其所在的數(shù)組下標位置# 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. 韓信點兵 . 韓信有一隊兵,他想知道有多少人,便讓士兵排隊報數(shù) : 按從 1至 5 報數(shù),最末一個士兵報的數(shù)為

22、1;按從 1 至 6 報數(shù),最末 一個士 兵報的數(shù)為 5; 按從 1 至 7 報數(shù),最末一個士兵報的數(shù)為 4; 最后再按從 1 至 11 報數(shù),最末一個士兵報的數(shù)為 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);面函數(shù) squeez () 的功能是刪除字符串 s 中所出現(xiàn)的與變量 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論