計算機(jī)二級C語言上機(jī)試題100套及答案_第1頁
計算機(jī)二級C語言上機(jī)試題100套及答案_第2頁
計算機(jī)二級C語言上機(jī)試題100套及答案_第3頁
計算機(jī)二級C語言上機(jī)試題100套及答案_第4頁
計算機(jī)二級C語言上機(jī)試題100套及答案_第5頁
已閱讀5頁,還剩323頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、上 機(jī) 題 庫第一部分 填空題注意:源程序存放在考生文件夾下的blank1.c中。1. 不得增行或刪行,也不得更改程序的結(jié)構(gòu)!2. 請在程序下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。1. 給定程序中,函數(shù)fun的功能是:計算出帶有頭接點的單向鏈表中各結(jié)點數(shù)據(jù)域之和作為函數(shù)值返回。#include #include #define n 8typedef struct list int data;struct list *next; slist;slist *creatlist(int *);void outlist(slist *);int fun( slist *h) sli

2、st *p; int s=0;p=h-next;while(p)/*found*/s+= p-_1_; data/*found*/p=p-_2_; nextreturn s;main( ) slist *head;int an=12,87,45,32,91,16,20,48;head=creatlist(a); outlist(head);/*found*/printf(nsum=%dn, fun(_3_); headslist *creatlist(int a ) slist *h,*p,*q; int i;h=p=(slist *)malloc(sizeof(slist);for(i=0;

3、 idata=ai; p-next=q; p=q;p-next=0;return h;void outlist(slist *h) slist *p;p=h-next;if (p=null) printf(the list is null!n);else printf(nhead );do printf(-%d, p-data); p=p-next; while(p!=null);printf(-endn);2. 給定程序中,函數(shù)fun的功能是:求出形參ss所指字符串?dāng)?shù)組中最長字符串的長度,其余字符串左邊用字符*補(bǔ)齊,使其與最長的字符串等長。字符串?dāng)?shù)組中工有m個字符串,且串長n。#includ

4、e #include #define m 5#define n 20void fun(char (*ss)n) int i, j, k=0, n, m, len;for(i=0; in) /*found*/n=len; k=_1_; i for(i=0; i=0; j-) lenssim-=ssij;for(j=0; jn-len; j+)/*found*/ssij=_3_; *main( )char smn=shanghai,guangzhou,beijing,tianjing,cchongqing;int i;printf(nthe original strings are :n);for

5、(i=0; im; i+) printf(%sn,ssi);printf(n);fun(ss);printf(nthe result:n);for(i=0; im; i+) printf(%sn,ssi);3. 人員記錄由編號和出生年,月,日組成,n名人員的數(shù)據(jù)已在主函數(shù)中存入結(jié)構(gòu)體數(shù)組std且編號唯一。函數(shù)fun 的功能是;找出指定編號人員的數(shù)據(jù),作為函數(shù)值返回,有主函數(shù)輸出,若指定編號不存在,返回數(shù)據(jù)中的編號為空串。#include #include #define n 8typedef struct char num10;int year,month,day ;stu;/*found*/

6、_1_fun(stu *std, char *num) stu int i; stu a=,9999,99,99;for (i=0; in; i+)/*found*/if( strcmp(_2_,num)=0 ) stdi.num/*found*/return (_3_); stdireturn a;main( )stu stdn= 111111,1984,2,15,222222,1983,9,21,333333,1984,9,1,444444,1983,7,15,555555,1984,9,28,666666,1983,11,15,777777,1983,6,22,888888,1984,8

7、,19;stu p; char n10=666666;p=fun(std,n);if(p.num0=0)printf(nnot found !n);else printf(nsucceed !n );printf(%s %d-%d-%dn,p.num,p.year,p.month,p.day);4. 給定程序中已建立一個帶有頭結(jié)點的單向鏈表,鏈表中的各結(jié)點按數(shù)據(jù)域遞增有序鏈接。函數(shù)fun 的功能:刪除鏈表中數(shù)據(jù)域值相同的結(jié)點,使之保留一個。#include #include #define n 8typedef struct list int data;struct list *next; s

8、list;void fun( slist *h) slist *p, *q;p=h-next;if (p!=null) q=p-next;while(q!=null) if (p-data=q-data) p-next=q-next;/*found*/free(_1_); q/*found*/q=p-_2_; nextelse p=q;/*found*/q=q-_3_; nextslist *creatlist(int *a) slist *h,*p,*q; int i;h=p=(slist *)malloc(sizeof(slist);for(i=0; idata=ai; p-next=q;

9、 p=q;p-next=0;return h;void outlist(slist *h) slist *p;p=h-next;if (p=null) printf(nthe list is null!n);else printf(nhead);do printf(-%d,p-data); p=p-next; while(p!=null);printf(-endn);main( ) slist *head; int an=1,2,2,3,4,4,4,5;head=creatlist(a);printf(nthe list before deleting :n); outlist(head);f

10、un(head);printf(nthe list after deleting :n); outlist(head);5. 函數(shù)fun 的功能是進(jìn)行數(shù)字字符轉(zhuǎn)換。若形參ch中是數(shù)字字符0 9,則0轉(zhuǎn)換成9, 1轉(zhuǎn)換成8, 2轉(zhuǎn)換成7 9轉(zhuǎn)換成0;若是其他字符則保持不變;并將轉(zhuǎn)換后的結(jié)果作為函數(shù)值返回.#include /*found*/_1_fun(char ch) char/*found*/if (ch=0 &_2_) ch=9/*found*/return 9- (ch-_3_); 0return ch ;main( ) char c1, c2;printf(nthe result :n

11、);c1=2; c2 = fun(c1);printf(c1=%c c2=%cn, c1, c2);c1=8; c2 = fun(c1);printf(c1=%c c2=%cn, c1, c2);c1=a; c2 = fun(c1);printf(c1=%c c2=%cn, c1, c2);6. 給定程序中,函數(shù)fun的功能是:對形參ss所指字符串?dāng)?shù)組中的m字符串按長度由短到長進(jìn)行排序。ss所指字符串?dāng)?shù)組中共有m個字符串,且串長n#include #include #define m 5#define n 20void fun(char (*ss)n) int i, j, k, nm; cha

12、r tn;for(i=0; im; i+) ni=strlen(ssi);for(i=0; im-1; i+) k=i;/*found*/for(j=_1_; jnj) k=_2_; jif(k!=i) strcpy(t,ssi);strcpy(ssi,ssk);/*found*/strcpy(ssk,_3_); tnk=ni;main( ) char smn=shanghai,guangzhou,beijing,tianjing,cchongqing;int i;printf(nthe original strings are :n);for(i=0; im; i+) printf(%sn,

13、ssi);printf(n);fun(ss);printf(nthe result :n);for(i=0; im; i+) printf(%sn,ssi);7. 函數(shù)fun的功能是:從三個形參a,b,c中找出中間的哪個數(shù),作為函數(shù)值返回。例如,當(dāng)a=3,b=5,c=4時,中數(shù)為4。#include int fun(int a, int b, int c) int t;/*found*/t = (ab) ? (bc? b :(ac?c:_1_) : (ac)?_2_ : (bc)?c:_3_);return t; 1. a 2. a 3.bmain( ) int a1=3, a2=5, a3=

14、4, r;r = fun(a1, a2, a3);printf(nthe middle number is : %dn, r);8. 給定程序中,函數(shù)fun的功能是:統(tǒng)計出帶有頭結(jié)點的單向鏈表中接點的個數(shù),存放在形參n所指的存儲單元中。#include #include #define n 8typedef struct list int data;struct list *next; slist;slist *creatlist(int *a);void outlist(slist *);void fun( slist *h, int *n) slist *p;/*found*/*n=_1_

15、;0p=h-next;while(p) (*n)+;/*found*/p=_2_; p-nextmain( ) slist *head;int an=12,87,45,32,91,16,20,48, num;head=creatlist(a); outlist(head);/*found*/fun(head,_3_); &numprintf(nnumber=%dn,num);slist *creatlist(int a ) slist *h,*p,*q; int i;h=p=(slist *)malloc(sizeof(slist);for(i=0; idata=ai; p-next=q; p

16、=q;p-next=0;return h;void outlist(slist *h) slist *p;p=h-next;if (p=null) printf(the list is null!n);else printf(nhead );do printf(-%d,p-data); p=p-next; while(p!=null);printf(-endn);9. 給定程序的功能是:調(diào)用函數(shù)fun將指定源文件中的內(nèi)容復(fù)制到指定的目標(biāo)文件中,復(fù)制成功時函數(shù)返回值為1,失敗時返回值為0。在復(fù)制的過程中,把復(fù)制的內(nèi)容輸出到終端屏幕。主函數(shù)中源文件名房子變量sfname中,目標(biāo)文件名放在變量tfn

17、ame中。#include #include int fun(char *source, char *target) file *fs,*ft; char ch;/*found*/if(fs=fopen(source,_1_)=null) rreturn 0;if(ft=fopen(target, w)=null)return 0;printf(nthe data in file :n);ch=fgetc(fs);/*found*/while(!feof(_2_) fs putchar( ch );/*found*/fputc(ch,_3_); ftch=fgetc(fs);fclose(fs

18、); fclose(ft);printf(nn);return 1;main( ) char sfname20 =myfile1,tfname20=myfile2;file *myf; int i; char c;myf=fopen(sfname,w);printf(nthe original data :n);for(i=1; i30; i+) c=a+rand( )%25;fprintf(myf,%c,c); printf(%c,c); fclose(myf);printf(nn);if (fun(sfname, tfname) printf(succeed!);else printf(f

19、ail!);10. 給定 程序中,函數(shù)fun的功能是:在形參s所指字符串中的每個數(shù)字字符之后插入一個*。例如,形參s所指字符串為:def35adh3kjsdf7.執(zhí)行結(jié)果為:def3*5*adh3*kjsdf7*#include void fun(char *s) int i, j, n;for(i=0; si!=0; i+)/*found*/if(si=0 _1_ sii; j-)/*found*/sj+1= _3_;sjsj+1=*;i=i+1;main( ) char s80=ba3a54cd23a;printf(nthe original string is : %sn,s);fun(

20、s);printf(nthe result is : %sn,s);11. 給定程序中,函數(shù)fun的功能是:將形參std所指結(jié)構(gòu)體數(shù)組中年齡最大者的數(shù)據(jù)作為函數(shù)值返回,并將 main函數(shù)輸出。#include typedef struct char name10;int age;std;std fun(std std, int n) std max; int i;/*found*/max=_1_; std0for(i=1; in; i+)/*found*/if(max.age_2_) max=stdi; stdi.agereturn max;main( ) std std5=aaa,17,bb

21、b,16,ccc,18,ddd,17,eee,15 ;std max;max=fun(std,5); printf(nthe result: n);/*found*/printf(nname : %s, age : %dn,_3_ ,max.age); 12. 給定程序中,函數(shù)fun 功能是:在帶有頭結(jié)點的單向鏈表中,查找數(shù)據(jù)域中為ch的結(jié)點,找到后通過函數(shù)值返回該結(jié)點在鏈表中所處的順序號;若不存在值為ch的結(jié)點,函數(shù)返回0值。#include #include #define n 8typedef struct list int data;struct list *next;

22、 slist;slist *creatlist(char *);void outlist(slist *);int fun( slist *h, char ch) slist *p; int n=0;p=h-next;/*found*/while(p!=_1_)null n+;/*found*/if (p-data=ch) return _2_; nelse p=p-next;return 0;main( ) slist *head; int k; char ch;char an=m,p,g,a,w,x,r,d;head=creatlist(a);outlist(head);printf(en

23、ter a letter:);scanf(%c,&ch);/*found*/k=fun(_3_);head,chif (k=0) printf(nnot found!n);else printf(the sequence number is : %dn,k);slist *creatlist(char *a) slist *h,*p,*q; int i;h=p=(slist *)malloc(sizeof(slist);for(i=0; idata=ai; p-next=q; p=q;p-next=0;return h;void outlist(slist *h) slist *p;p=h-n

24、ext;if (p=null) printf(nthe list is null!n);else printf(nhead);do printf(-%c,p-data); p=p-next; while(p!=null);printf(-endn);13. 給定程序的功能是:從鍵盤輸入若干行文本(每行不超過80個字符),寫到文件myfile4.txt 中,用-1作為字符串輸入結(jié)素的標(biāo)志。然后將文件的內(nèi)容讀出顯示在屏幕上。文件的讀寫分別由自定義函數(shù)read text 和 write text實現(xiàn).#include #include #include void writetext(file *);

25、void readtext(file *);main( ) file *fp;if(fp=fopen(myfile4.txt,w)=null) printf( open fail!n); exit(0); writetext(fp);fclose(fp);if(fp=fopen(myfile4.txt,r)=null) printf( open fail!n); exit(0); readtext(fp);fclose(fp);/*found*/void writetext(file _1_ ) *fw char str81;printf(nenter string with -1 to en

26、d :n);gets(str);while(strcmp(str,-1)!=0) /*found*/fputs(_2_,fw); fputs(n,fw); strgets(str);void readtext(file *fr) char str81;printf(nread file and output to screen :n);fgets(str,81,fr);while( !feof(fr) ) /*found*/printf(%s,_3_); strfgets(str,81,fr);14. 給定程序中,函數(shù)fun的功能是:有n x n矩陣,根據(jù)給定的m(m=n)值,將每個元素中的值

27、均右移m個位置,左邊置為0。例如,n=3,m=2,有下列矩陣123 001456 程序執(zhí)行結(jié)果為004789007#include #define n 4void fun(int (*t)n, int m) int i, j;/*found*/for(i=0; i=0; j-)/*found*/tij+_2_ =tij; m/*found*/for(j=0; j_3_; j+)mtij=0;main( ) int tn=21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10, i, j, m;printf(nthe original array:n);f

28、or(i=0; in; i+) for(j=0; jn; j+)printf(%2d ,tij);printf(n);printf(input m (m=%d): ,n);scanf(%d,&m);fun(t,m);printf(nthe result is:n);for(i=0; in; i+) for(j=0; jn; j+)printf(%2d ,tij);printf(n);15. 函數(shù)fun的功能是; 把形參a所指數(shù)組中的最大值放雜a0中,接著求出a所指數(shù)組中的最小值防在 a1中;再把a(bǔ)所指數(shù)組元素中的次大值a2中,把a(bǔ)所指數(shù)組的數(shù)據(jù)最初排列為:1,4,2,3,9,6,5,8,7,則

29、按規(guī)則移動后,數(shù)據(jù)排列為:9,1,8,2,7,3,6,4,5。形參n中存放a所指數(shù)組中數(shù)據(jù)的個數(shù)。#include #define n 9/*found*/void fun(int _1_ , int n) *a int i, j, max, min, px, pn, t;/*found*/for (i=0; in-1; i+=_2_)2 max = min = ai;px = pn = i;/*found*/for (j=_3_; jn; j+) i if (max aj) min = aj; pn = j; if (px != i) t = ai; ai = max; apx = t;if

30、 (pn = i) pn= px;if (pn != i+1) t = ai+1; ai+1 = min; apn = t; main( ) int bn=1,4,2,3,9,6,5,8,7, i;printf(nthe original data :n);for (i=0; in; i+) printf(%4d , bi);printf(n);fun(b, n);printf(nthe data after moving :n);for (i=0; in; i+) printf(%4d , bi);printf(n);16. 給定程序中,函數(shù)fun的功能是;求ss所指字符串?dāng)?shù)組中長度最廠的字

31、符串所在的行下標(biāo),作為函數(shù)值返回,并把其串長防在形參n所指變量中。ss所指字符串?dāng)?shù)組中共有m個字符串,且串長n.#include #define m 5#define n 20/*found*/int fun(char (*ss) _1_, int *n) n int i, k=0, len=0;for(i=0; i*n) /*found*/*n=_3_;lenk=i;return(k);main( ) char ssmn=shanghai,guangzhou,beijing,tianjing,cchongqing;int n,k,i;printf(nthe original strings are :n);for(i=0;im;i+)puts(ssi);k=fun(ss,&n);printf(nthe length of longest string is : %dn,n);printf(nthe longest string is : %sn,ssk);17. 函數(shù)fun的功能是:逆置數(shù)組元素中的值。例如:若a所指數(shù)組中的數(shù)據(jù)依次為:1

溫馨提示

  • 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

提交評論