技能考試試卷C語言真題_第1頁
技能考試試卷C語言真題_第2頁
技能考試試卷C語言真題_第3頁
技能考試試卷C語言真題_第4頁
技能考試試卷C語言真題_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、第一部分【程序填空】第一套:題目:函數(shù)gcd()計算整型數(shù)組a中相鄰兩元素的最大公約數(shù),最小公倍數(shù),其中最大公約數(shù)存入數(shù)組b中,最小公倍數(shù)存入數(shù)組c中。-注意:請勿改動主函數(shù)main()中的其他內(nèi)容。-#include <stdio.h>#include <conio.h>void gcd(int a,int n,int b,int c) int i,x,y,z;/*SPACE*/ for(i=0;i<【?】;i+) x=ai; y=ai+1; while(z=x%y) x=y;y=z; bi=y;/*SPACE*/ ci=ai*ai+1/【?】; int mai

2、n() int a5=8,12,5,7,14; int b4,c4; int i; gcd(a,5,b,c); for(i=0;i<5;i+) printf("%dt",ai); printf("n"); for(i=0;i<4;i+) printf("%dt",bi); printf("n"); for(i=0;i<4;i+) printf("%dt",ci); printf("n"); getch(); return 0;第二套題目:函數(shù)reverse(

3、)對字符串str進(jìn)行逆序。#include<stdio.h>#include<string.h>#include<conio.h>void reverse(char str) int len, j; char c;/*SPACE*/ len = 【?】(str);/*SPACE*/ for (j=len-1; 【?】; j-) c=strj; strj=strlen-1-j; strlen-1-j=c; int main() char a80; printf("Please enter a string: "); gets(a); rev

4、erse(a); printf("The inversed string is: "); puts(a); getch(); return 0;第三套題目:對主函數(shù)main()中數(shù)組a進(jìn)行處理:如果相鄰元素相同則保留一個。例如對數(shù)組a處理后,它的前11個元素為-5,7,-4,25,0,2,4,16,8,5,20。#include <stdio.h>#include <conio.h>int main() int a20=-5,-5,7,-4,-4,25,25,0,0,0,2,4,16,16,8,5,5,5,5,20; int i,prev,next;

5、 prev=0; next=1; while(next<20)/*SPACE*/ if(aprev!=【?】) a+prev=anext; next+; /*SPACE*/ for(i=0;i【?】prev;i+) printf("%d ",ai); printf("n"); getch(); return 0;第四套題目:程序輸出由03四個數(shù)字組成的符合下列條件的4位整數(shù): 1. 每個4位整數(shù)中,03四個數(shù)字只能出現(xiàn)一次; 2. 百位數(shù)不能為3,十位數(shù)不能為2。#include <stdio.h>#include <conio.

6、h>int main() int g,s,b,q; int num=0; for(b=0;b<4;b+) if(b=3) continue; for(s=0;s<4;s+) if(b=s)|(s=2) continue;/*SPACE*/ for(q=【?】;q<4;q+) if(q=b)|(q=s) continue;/*SPACE*/ g=【?】-q-b-s; printf("%dn",q*1000+b*100+s*10+g); num+; printf("%dn",num); getch(); return 0;第五套題目:

7、在一維數(shù)組a中找出最大,最小元素,并將最大元素和數(shù)組最后一個元素交換,最小元素和數(shù)組首元素交換。#include <stdio.h>#include <conio.h>int main() int a10=15,8,12,6,10,1,4,5,9,-3; int i,t,max_index,min_index; max_index=min_index=0; for(i=1;i<10;i+) if(ai>amax_index) max_index=i; if(ai<amin_index) min_index=i; t=a0;a0=amin_index;a

8、min_index=t;/*SPACE*/ if(max_index=【?】) t=amin_index;amin_index=a9;a9=t; else/*SPACE*/ 【?】; for(i=0;i<10;i+) printf("%dt",ai); printf("n"); getch(); return 0;=第二部分【程序改錯】第一套題目:主函數(shù)main()調(diào)用函數(shù)change()將二維數(shù)組strrow中的字符按列存入一維數(shù)組strcol中。下面給定的程序存在錯誤,請改正。#include <stdio.h>#include &

9、lt;conio.h>/*FOUND*/void change(char t5,char s) int i,j; for(j=0;j<5;j+) for(i=0;i<3;i+)/*FOUND*/ s3*j+i=tji;/*FOUND*/ sj=0;int main() char strrow5='C','r','r',' ','s',' ','o','a','T','t','P','g'

10、,'m','e','!' char strcol16; change(strrow,strcol); puts(strcol); getch(); return 0;第二套題目:在主函數(shù)中main()中輸入年、月、日,然后計算該天是這一年的第幾天。其中函數(shù)LeapYear()是判斷某年是否為閏年。下面給定的程序存在錯誤,請改正。#include <stdio.h>#include <conio.h>int LeapYear(int year)/*FOUND*/ return (year%4=0 && yea

11、r%100) && (year%400=0);int main() int mon_days211=31,28,31,30,31,30,31,31,30,31,30,31,29,31,30,31,30,31,31,30,31,30; int year,mon,day,days; int i; scanf("%d %d %d",&year,&mon,&day); days=day;/*FOUND*/ for(i=0;i<mon-2;i+)/*FOUND*/ days=mon_daysLeapYear(year)i; printf(

12、"%dn",days); getch(); return 0;第三套題目:主函數(shù)main()調(diào)用函數(shù)MyStrcat()將字符串src連接到字符串dstStr后面。下面給定的程序存在錯誤,請改正。#include <stdio.h>#include <conio.h>void MyStrcat(char dstStr, char srcStr) int i,j; i=j=0;/*FOUND*/ while(dstStri+) i+; i-=1; while(srcStrj) dstStri=srcStrj; i+;j+; /*FOUND*/ srcS

13、tri=0;int main() char dst100="This is " char src20="C Test!"/*FOUND*/ MyStrcat(dst100,src20); puts(dst); getch(); return 0;第四套題目:程序去除主函數(shù)main()中字符串str中的非字母字符。函數(shù)IsAlpha()的功能是判斷字符c是否為字母。#include <stdio.h>#include <conio.h>int IsAlpha(char c)/*FOUND*/ return (c>='a

14、' && c<='z') && (c>='A' && c<='Z');int main() char str="/* One World,One Dream! */" int prev,next; prev=next=0; while(strnext) if(IsAlpha(strnext)/*FOUND*/ strnext=strprev; prev+; next+; /*FOUND*/ strnext=0; puts(str); getch(); r

15、eturn 0;第五套題目:主函數(shù)main()統(tǒng)計字符串str中的各字母(不區(qū)分大小寫)及其他字符出現(xiàn)的次數(shù),并顯示統(tǒng)計結(jié)果(次數(shù)為0,則不顯示)。下面給定的程序存在錯誤,請改正。#include <stdio.h>#include <conio.h>#include <ctype.h>int main() char str="-JiangSu Teachers University of Technology-" int chnum27=0,i=-1;/*FOUND*/ while(stri) if(isalpha(stri)/*FOU

16、ND*/ chnumtoupper(stri)-97+; else chnum26+; for(i=0;i<27;i+)/*FOUND*/ if(chnumi=0) if(i=26) printf("other ch=%dn",chnum26); else printf("%c(%c)=%dn",i+65,i+97,chnumi); getch(); return 0;第三部分【程序設(shè)計題】第一套題目:假設(shè)英文大小寫字母的權(quán)值分別為: A-E,a-e 1; F-J,f-j 2; K-O,k-o 3; P-T,p-t 4; U-Y,u-y 5; Z,

17、z 6 計算主函數(shù)main()中數(shù)組words中的各英文單詞的權(quán)重(英文單詞的權(quán)重為該單詞各字母權(quán)值之和)。例如: 單詞"World"的權(quán)重為16(W為5;o為3;r為4;l為3;d為1,5+3+4+3+1=16)。編寫程序: 1. 編寫函數(shù)void calculate(char w20,int n,int p),計算數(shù)組w中n個英文單詞的權(quán)重,并將權(quán)重存放在數(shù)組p中。 2. 編寫函數(shù)void sort(int p,int n,char w20),對數(shù)組p中n個單詞的權(quán)重進(jìn)行降序排序,權(quán)重所對應(yīng)單詞在數(shù)組w中的位置也要作相應(yīng)調(diào)整。-注意:請勿改動主函數(shù)main()中的任何語

18、句。-*/#include <stdio.h>#include <ctype.h>#include <stdlib.h>#include <conio.h>#include <string.h>void calculate(char w20,int n,int p)/*Program*/* End */void sort(int p,int n,char w20)/*Program*/* End */int main() char words520="JiangSu","Teachers",&q

19、uot;University","of","Technology" int value5=0; int i; FILE *fp; if(fp=fopen("DATA.TXT","w")=NULL) printf("File open errorn"); exit(0); calculate(words,5,value); for(i=0;i<5;i+) fprintf(fp,"%-20s%4dn",wordsi,valuei); printf("%-

20、20s%4dn",wordsi,valuei); printf("n"); fprintf(fp,"n"); sort(value,5,words); for(i=0;i<5;i+) fprintf(fp,"%-20s%4dn",wordsi,valuei); printf("%-20s%4dn",wordsi,valuei); fclose(fp); getch(); return 0;第二套題目:主函數(shù)main()中str_b是這樣的字符串:若干個長度不等的,連續(xù)的'0'、

21、9;1'字符組成的字符子串被長度不等的'.'字符間隔。將連續(xù)的'0'、'1'字符子串看成是二進(jìn)制整數(shù)。要求將其轉(zhuǎn)換為十進(jìn)制整數(shù)。其中字符子串的首字符代表二進(jìn)制數(shù)的符號位,'0'表示正數(shù),'1'表示負(fù)數(shù)。例如:"0111"表示7,"1111"表示-7。編寫程序: 1. 編寫函數(shù)int convert(char b,int d),將字符數(shù)組b中連續(xù)二進(jìn)制數(shù)字字符子串轉(zhuǎn)換為十進(jìn)制整數(shù),并存入整型數(shù)組d中。函數(shù)返回十進(jìn)制數(shù)的個數(shù)。 2. 編寫函數(shù)void sort(int d

22、,int n),對數(shù)組d中n個元素進(jìn)行升序排序。#include<stdio.h>#include<stdlib.h>#include<conio.h>int convert(char b,int d)/*Program*/* End */void sort(int d,int n)/*Program*/* End */int main() char str_b100=".111100.01111.01100111.0111.110000.011." int int_d10; int i,k; FILE *fp; if(fp=fopen(

23、"DATA.TXT","w")=NULL) printf("File open errorn"); exit(0); k=convert(str_b,int_d); for(i=0;i<k;i+) printf("%dt",int_di); fprintf(fp,"%dt",int_di); printf("n"); fprintf(fp,"n"); sort(int_d,k); for(i=0;i<k;i+) printf("%dt

24、",int_di); fprintf(fp,"%dt",int_di); printf("n"); fprintf(fp,"n"); fclose(fp); getch(); return 0;第三套題目:主函數(shù)main()的一維數(shù)組a中元素為非0整數(shù)。程序?qū)⒇?fù)數(shù)存入數(shù)組b的左側(cè),正數(shù)存入數(shù)組b的右側(cè),并將數(shù)組b左側(cè)的負(fù)數(shù)按升序,右側(cè)的正數(shù)按降序重新排列。編寫程序: 1. 編寫函數(shù)int split(int a,int b,int len),將數(shù)組a中l(wèi)en個整數(shù)分別存放在數(shù)組b的左右兩側(cè),其中負(fù)數(shù)存入數(shù)組b的左側(cè),正數(shù)存入

25、數(shù)組b的右側(cè)。函數(shù)返回數(shù)組b中最后一個負(fù)數(shù)的下標(biāo)。 2. 編寫void sort(int a,int left,int right,int order)函數(shù),對數(shù)組a中下標(biāo)在left, right范圍內(nèi)的元素進(jìn)行升序或降序排序。當(dāng)order=1時,進(jìn)行降序排序,當(dāng)order=0時,進(jìn)行升序排序。#include<stdio.h>#include<stdlib.h>#include<conio.h>int split(int a,int b,int len)/*Program*/* End */void sort(int a,int left,int righ

26、t,int order)/*Program*/* End */int main() int a10=7,-2,3,14,-5,-6,5,22,-4,8,b10; int i,mid; FILE *fp; if(fp=fopen("DATA.TXT","w")=NULL) printf("File open errorn"); exit(0); mid=split(a,b,10); for(i=0;i<10;i+) printf("%dt",bi); fprintf(fp,"%dt",bi)

27、; printf("n"); fprintf(fp,"n"); sort(b,0,mid,0); sort(b,mid+1,9,1); for(i=0;i<10;i+) printf("%dt",bi); fprintf(fp,"%dt",bi); printf("n"); fprintf(fp,"n"); fclose(fp); getch(); return 0;第四套題目:主函數(shù)main()中一維數(shù)組ring9存放數(shù)字1-9。將ring看成是一個首尾相接的環(huán)。將9

28、個數(shù)分成3段,第1段為1個2位數(shù),第2段為1個3位數(shù),第3段為1個4位數(shù),程序計算這3段數(shù)之和。要求從環(huán)的第1個數(shù)開始,直到第9個數(shù),依上述規(guī)則進(jìn)行處理。同時在這些和中尋找77的整數(shù)倍的數(shù)。例如: 從環(huán)的第一個數(shù)開始的3段數(shù)為12,345,6789,其和為7146; 從環(huán)的第二個數(shù)開始的3段數(shù)為23,456,7891,其和為8370; . 從環(huán)的第九個數(shù)開始的3段數(shù)為91,234,5678,其和為6003;編寫程序: 1. 編寫函數(shù)void calculate(int ring,int st),從數(shù)組ring的第1個數(shù)開始,將9個數(shù)分成3段,第1段為1個2位數(shù),第2段為1個3位數(shù),第3段為1個

29、4位數(shù),程序計算所有3段數(shù)之和。并將所有3段數(shù)之和存入數(shù)組st中。 2. 編寫函數(shù)int check(int st,int t77),在數(shù)組st中尋找77的整數(shù)倍的數(shù),存入數(shù)組t77中,函數(shù)返回其個數(shù)。#include<stdio.h>#include<stdlib.h>#include<conio.h>void calculate(int ring,int st)/*Program*/* End */int check(int st,int t77)/*Program*/* End */int main() int ring9=1,2,3,4,5,6,7,

30、8,9; int st9,t779,i,k; FILE *fp; if(fp=fopen("DATA.TXT","w")=NULL) printf("File open errorn"); exit(0); calculate(ring,st); for(i=0;i<9;i+) printf("%dt",sti); fprintf(fp,"%dt",sti); printf("n"); fprintf(fp,"n"); k=check(st,t77); for(i=0;i<k;i+) printf("%dt",t77i); fprintf(f

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論