二級(jí)語言100套上機(jī)試題文本可到手機(jī)_第1頁
二級(jí)語言100套上機(jī)試題文本可到手機(jī)_第2頁
二級(jí)語言100套上機(jī)試題文本可到手機(jī)_第3頁
二級(jí)語言100套上機(jī)試題文本可到手機(jī)_第4頁
二級(jí)語言100套上機(jī)試題文本可到手機(jī)_第5頁
已閱讀5頁,還剩360頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

C100套上機(jī)試題1套:給定程序的功能是調(diào)用fun函數(shù)建立班級(jí)。中記錄每位學(xué)生的、和。班級(jí)的人數(shù)和學(xué)生的信息從鍵盤讀入,每個(gè)人的信息作myfile5.dat的二進(jìn)制文件中。BLANK1.C中。#include<stdio.h>#includestdlib.h>#defineN5typedefstruct{intcharname[10]; voidintfun( { *fp;inti;printf("\nOutputdatatofile!\n");for(i=0;i<N;i++)fwrite(&std[i],sizeof(STYPE),1, return}{STYPEs[10]={intk;if{printf("Succeed!");check();}}void{FILE*fp;inti;STYPEs[10];{printf("Fail!!\n");exit(0);printf("\nReadfileandoutputtoscreen:\n");printf("\nnumname for(i=0;i<N;printf("%6d%s }}本題是要求把指定的學(xué)生記錄輸出到指定的文件中。程序有三處要填上適當(dāng)?shù)膬?nèi)容,第一處:結(jié)構(gòu)定義自變量,因此應(yīng)填寫STYPE第二處:在所填行的下面一行,使用fopen每三處:fwritefwrite參數(shù)的使用要求,所以只能填寫文件流變量fp。MODI1.C中函數(shù)funs中的字符按正序存放tst串的后面。s中的字符串為:"ABCDE"時(shí),main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#include<stdio.h>#include<string.h>voidfun(char*s,char{inti,sl=for(i=0;i<=s1;i++)t[i]=for(i=0;i<sl;\TABt[sl+i]=s[sl-i-t[sl]='\0';}{chars[100],printf("\nPleaseenterstrings:");scanf("%s",fun(s,printf("Theresultis:%s\n",}fun的功能是:將兩個(gè)兩位數(shù)的正整數(shù)a、b合并形成一個(gè)整數(shù)放在c合并的方式是:將a數(shù)的十位和個(gè)位數(shù)依次放在cb數(shù)的十位和個(gè)位數(shù)依次放在c數(shù)的百位和個(gè)位上。例如,當(dāng)a=45,b=12時(shí),調(diào)用該函數(shù)后,c=4152注意:PROG1.CIN.DAT中的數(shù)據(jù)不得修改。mainfun的花括號(hào)中填#includevoidfun(inta,intb,long{}{inta,b;longprintf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%d\n",c);}NONO({/**/FILE*rf,*wf;inti,a,b;longcrf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c)}fclose(rf);fclose(wf)}a十位數(shù)字的方法:a/10a#includevoidfun(inta,intb,long{}{inta,b;longprintf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%d\n",c);}NONO({/**/FILE*rf,*wf;inti,a,b;longcrf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c)}fclose(rf);fclose(wf)}2套:給定程序的功能是:從鍵盤輸入若干行文本(80個(gè)字符,寫到myfile4.txt中,用-1作為字符串輸入結(jié)束的標(biāo)志。然后將文件的內(nèi)容讀出顯ReadTextWriteText實(shí)現(xiàn)。BLANK1.C中。#include<stdio.h>#include<string.h>#include<stdlib.h>voidWriteText(FILE*);voidReadText(FILE*);{FILE{printf("openfail!!\n");exit(0);}{printf("openfail!!\n");exit(0);}}voidWriteText(FILE {charprintf("\nEnterstringwith-1toend:\n"); ,fw);fputs("\n",fw);}}{charprintf("\nReadfileandoutputtoscreen:\n");while(!feof(fr)) }}本題要求是把鍵盤上輸入的內(nèi)容寫到指定的文件中。程序有三處要填上適當(dāng)?shù)膬?nèi)容,fputs("\n",fw);分析可知:由于文件流變量fw在函數(shù)體沒有定義過,所以本處應(yīng)填*fw或fw[]。第二處:通過while循環(huán)語句,把鍵盤上輸入的內(nèi)容,要寫入到指定的文件中,鍵盤上輸入strstr。str中,最后在屏str。MODI1.C中函數(shù)fun的功能是:s中奇數(shù)位上的數(shù),依次構(gòu)成一個(gè)新數(shù)放在t中。仍在,低位仍在低位。s中的數(shù)為:7654321時(shí),t中的數(shù)為:7531。main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#includevoidfun(longs,longt){long*t=s%10;while(s>{s=*t=s%10*sl+\TABsl=}}{longs,printf("\nPleaseenters:");scanf("%ld",&s);fun(s,&t);printf("Theresultis:%ld\n",}fun中使用了*t,但在函數(shù)定義時(shí)沒有使用*t,所以應(yīng)改為:voidfun(longs,long*t)。fun的功能是:將兩個(gè)兩位數(shù)的正整數(shù)a、b合并形成一個(gè)整數(shù)放在c合并的方式是:將a數(shù)的十位和個(gè)位數(shù)依次放在cb數(shù)的十位和個(gè)位數(shù)依次放在c數(shù)的千位和十位上。例如,當(dāng)a=45,b=12時(shí),調(diào)用該函數(shù)后,c=1524注意:PROG1.CIN.DAT中的數(shù)據(jù)不得修改。mainfun的花括號(hào)中填入#includevoidfun(inta,intb,long{}{inta,b;longc;printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);}NONO({/**/FILE*rf,*wf;inti,a,b;longcrf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c)}fclose(rf);fclose(wf)}a十位數(shù)字的方法:a/10a個(gè)位數(shù)字的方法:a%10#includevoidfun(inta,intb,long{}{inta,b;longc;printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);}NONO({/**/FILE*rf,*wf;inti,a,b;longcrf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c)}fclose(rf);fclose(wf)}3套:給定程序中,函數(shù)fun的功能是:將自然數(shù)1~10以及它們的平寫到名BLANK1.C中。#include<math.h>#include<stdio.h>intfun(char*fname{FILE*fp;inti,n;floatx;if((fp=fopen(fname,"w"))==NULL)return0; ,"%d%f\n",i,sqrt((double)i)); printf("\nThedatainfile return0;{printf("%d%f\n",n,x);fscanf(fp,"%d%f",&n,&x);}return}{charfname[]="myfile3.txt";}第一處:intfprintf(FILE*streamconstchar*formatargument,…]);因此本處fp。文件名,所以本處只能寫文件名變量fname或者直接給出文件名"myfile3.dat"。MODI1.Cfunn個(gè)無序整數(shù)從小到大排序。main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#include<stdio.h>#include<stdlib.h>fun(intn,int*a){inti,j,p,for(j=0;j<n-1;j++{p=for(i=j+1;i<n-1;i++)if(a[p]>a[i]if(p!=j{t=a[j];a[j]=a[p];a[p]=t;}}putarr(intn,int*z{intfor(i=1;i<=n;i++,z++{printf("%4d",*zif(!(i%10))printf("\n"}}{intaa[20]={9,3,0,4,1,2,5,6,8,10,7},printf("\n\nBeforesorting%dnumbers:\n",n);putarr(n,aa);fun(n,aa);printf("\nAftersorting%dnumbers:\n",n);putarr(n,aa}第一處:for循環(huán)的終止值應(yīng)該<n或者是<=n-1fun的功能是:將兩個(gè)兩位數(shù)的正整數(shù)a、b合并形成一個(gè)整數(shù)放在c中。合并的方式是:ac數(shù)的個(gè)位和百位上b數(shù)的十位和個(gè)位數(shù)依次放在c數(shù)的十位和千位上。例如,當(dāng)a=45,b=12時(shí),調(diào)用該函數(shù)后c=2514:mainfun的花括號(hào)中填入#includevoidfun(inta,intb,long{}{inta,b;longc;printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);}NONO({/**/FILE*rf,*wf;inti,a,b;longcrf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c)}fclose(rf);fclose(wf)}a十位數(shù)字的方法:a/10a個(gè)位數(shù)字的方法:a%10#includevoidfun(inta,intb,long{}{inta,b;longc;printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);}NONO({/**/FILE*rf,*wf;inti,a,b;longcrf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c)}fclose(rf);fclose(wf)}4套:給定程序的功能是:調(diào)用函數(shù)fun將指定源文件中的內(nèi)容到指定的目sfname中,目標(biāo)文件名放tfname中。BLANK1.C中。#include<stdio.h>#includeintfun(char*source,char*{FILE*fs,*ft;charif((fs=fopen(source, return0;if((ft=fopen(,"w"))==NULL)return0;printf("\nThedatainfile:\n"); {putchar(ch }fclose(fs);fclose(ft);return}{charsfname[20]="myfile1",tfname[20]="myfile2";FILE*myf;inti;charc;printf("\nTheoriginaldata:\n");for(i=1;i<30;i++){c='A'+rand()%25;fprintf(myf,"%c",c);printf("%c",c);}if(fun(sfname,tfname))printf("Succeed!");elseprintf("Fail!");}本題要求是把一個(gè)文件中的內(nèi)容到另一個(gè)文件中。程序有三處要填上適當(dāng)?shù)膬?nèi)容,fs第二處:用while循環(huán)來判斷源文件是否已讀到文件結(jié)束符,intfeof(FILE*stream),因此,此處只能填寫fs。第三處:把已經(jīng)的字符寫入目標(biāo)文件中,打開寫文件操作的流是ft,因此,此處只能ft。MODI1.C中函數(shù)fun的功能是:將長整型數(shù)中每一位上為偶數(shù)的數(shù)依次取出,構(gòu)成一個(gè)新數(shù)放在t中。仍在,低位仍在低位。s中的數(shù)為:87653142時(shí),t中的數(shù)為:8642。main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#includevoidfun(longs,long{intd;longsl=1;*t=while(s>{d=if(d%2=0){*t=d*sl+*t;sl*=10;}s\=10;}}{longs,printf("\nPleaseenters:");scanf("%ld",&s);fun(s,&t);printf("Theresultis:%ld\n",}fun的功能是:將兩個(gè)兩位數(shù)的正整數(shù)a、b合并形成一個(gè)整數(shù)放在c合并的方式是:將a數(shù)的十位和個(gè)位數(shù)依次放在cb數(shù)的十位和個(gè)位數(shù)依次放在c數(shù)的百位和個(gè)位上。例如,當(dāng)a=45,b=12時(shí),調(diào)用該函數(shù)后,c=5142注意:PROG1.CIN.DAT中的數(shù)據(jù)不得修改。mainfun的花括號(hào)中填入#includevoidfun(inta,intb,long{}{inta,b;longc;printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);}NONO({/**/FILE*rf,*wf;inti,a,b;longcrf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c)}fclose(rf);fclose(wf)}a十位數(shù)字的方法:a/10a個(gè)位數(shù)字的方法:a%10#includevoidfun(inta,intb,long{}{inta,b;longc;printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);}NONO({/**/FILE*rf,*wf;inti,a,b;longcrf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d,%d",&a,&b);fun(a,b,&c);fprintf(wf,"a=%d,b=%d,c=%ld\n",a,b,c)}fclose(rf);fclose(wf)}5套:域中的數(shù)據(jù)遞增有序。函數(shù)fun的功能是:把形參x的值放入一個(gè)新結(jié)點(diǎn)并插入到鏈表中,后各結(jié)點(diǎn)數(shù)據(jù)域的值仍保持遞增有序。}}#include<stdio.h>#include<stdlib.h>#defineN8typedefstructlist{intdata;structlist*next;}voidfun(SLIST*h,int{SLIST*p,*q,s=(SLIST p=h-while(p!=NULL&&x>p->data) p=p-}s- }SLIST*creatlist(int{SLIST*h,*p,*q;inth=p=(SLIST*)malloc(sizeof(SLIST));for(i=0;i<N;i++){q=(SLIST*)malloc(sizeof(SLIST));q->data=a[i];p->next=q;p=q;}returnh;}voidoutlist(SLIST{SLISTp=h-if(p==NULL)printf("\nThelistisNULL!\n");{do{printf("->%d",p->data);p=p->next;}while(p!=NULL);}{SLIST*head;intintprintf("\nThelistbeforeinserting:\n");outlist(head);printf("\nEnteranumber:");scanf("%d",&x);printf("\nThelistafterinserting:\n");}本題是要求在一個(gè)有序的鏈表中一個(gè)數(shù),后各結(jié)點(diǎn)仍然是有序的。程序有三funsdata是一個(gè)整型變量,x傳入,因此應(yīng)填xpx>p->data時(shí),那么再移動(dòng)鏈表指針到下一個(gè)結(jié)果,再進(jìn)行判斷是否s,snextpqnexts完成**************************************************************給定程序OD1.C中函數(shù)funnum252202。main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#include<stdio.h>longfun(longnum){longk;{k*=num%10num\=10;}while(num);return(k);main({longnprintf("\Pleaseenteranumber:");scanf("%ld",&n);printf("\n%ld\n",fun(n));}funn門課程的平均分,計(jì)算結(jié)果作為函5門課程的成績是:90.5,72,80,61.5,注意:PROG1.Cmain和其它函數(shù)中的任何內(nèi)容,fun的花括號(hào)中填入#includefloatfun(float*a,intn{}{floatscore[30]={90.5,72,80,61.5,55},aver;aver=fun(score,5);printf("\agescoreis:%5.2f\n",aver);NONO();}NONO({/**/FILE*fp,*wf;inti,jfloataver,score[5]fp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){for(j=0;j<5;j++)fscanf(fp,"%f,",&score[j]);aver=fun(score,5);fprintf(wf,"%5.2f\n",aver)}fclose(fp);fclose(wf)}#includefloatfun(float*a,intn{intfloatfor(i=0;i<n;i++)ave=ave+a[i];return}{floatscore[30]={90.5,72,80,61.5,55},aver;aver=fun(score,5);printf("\ agescoreis:%5.2f\n",aver);NONO();}NONO({/**/FILE*fp,*wf;inti,jfloataver,score[5]fp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){for(j=0;j<5;j++)fscanf(fp,"%f,",&score[j]);aver=fun(score,5);fprintf(wf,"%5.2f\n",aver)}fclose(fp);fclose(wf)}6套:給定程序中已建立一個(gè)帶有頭結(jié)點(diǎn)的單向鏈表,main函數(shù)中將多次調(diào)用函數(shù),每調(diào)用一次fun函數(shù),輸出鏈表尾部結(jié)點(diǎn)中的數(shù)據(jù),并該結(jié)點(diǎn),使鏈表BLANK1.C中。#include<stdio.h>#includestdlib.h>#defineN8typedefstruct{intdata;structlist*next;}voidfun(SLIST{SLIST*t,*s;t=p->next;while(t->next!={ }printf("%d", s- }SLIST*creatlist(int{SLIST*h,*p,*q;inth=p=(SLIST*)malloc(sizeof(SLIST));for(i=0;i<N;i++){q=(SLIST*)malloc(sizeof(SLIST));q->data=a[i];p->next=q;p=q;}returnh;}voidoutlist(SLIST{SLISTp=h-if(p==NULL)printf("\nThelistisNULL!\n");{do{printf("->%d",p->data);p=p->next;}while(p!=NULL);}}{SLISTintprintf("\nOutputfromhead:\n");outlist(head);printf("\nOutputfromtail:\n");while(head->next!=NULL){printf("\nOutputfromheadagain:\n");}}本題是對(duì)已經(jīng)建立的鏈表,通過調(diào)用一次函數(shù)就輸出鏈表尾部的數(shù)據(jù)。程序有三處要MODI1.C中函數(shù)fun的功能是:將字符串中的字符按逆序輸出,但不改例如,若字符串為abcd,則應(yīng)輸出:dcbamain函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#includefun(chara){if(*a{fun(a+1)printf("%c"*a);}}main({charprintf("處理前字符串=%s\n處理后字符串s);fun(s);printf("\n");}a應(yīng)定義為字符串指針。beijingCRshanghaiCR>(<CR>為回車鍵注意:PROG1.Cmain和其它函數(shù)中的任何內(nèi)容,fun的花括號(hào)中填入#includechar*fun(char*s,char{}main({chara[20],b[20];printf("Input1thstring:");gets(a);printf("Input2thstring:");gets(b);printf("%s\n",fun(a,b));NONO();}NONO({/**/FILE*fp,*wf;intichara[20],b[20]fp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%s%s",a,b)fprintf(wf,"%s\n",fun(a,b))}fclose(fp);fclose(wf)}#includechar*fun(char*s,char{intchar*p=s,*q=t;for(i=0;*p&&*q;i++){p++;q++;}if(*p==0&&*q==0)returns;if(*p)returns;elsereturnt}main({chara[20],b[20];printf("Input1thstring:");gets(a);printf("Input2thstring:");gets(b);printf("%s\n",fun(a,b));NONO();}NONO({/**/FILE*fp,*wf;intichara[20],b[20]fp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%s%s",a,b)fprintf(wf,"%s\n",fun(a,b))}fclose(fp);fclose(wf)}7套:增有序。函數(shù)fun的功能是:刪除鏈表中數(shù)據(jù)域值相同的結(jié)點(diǎn),使之只保留一BLANK1.C中。#include<stdio.h>#include<stdlib.h>#defineN8typedefstructlist{intdata;structlist*next;}voidfun(SLIST{SLIST*p,*q;if{q=p->next;{if(p->data==q-{p->next=q- }{- }}}}SLIST*creatlist(int{SLIST*h,*p,*q;inth=p=(SLIST*)malloc(sizeof(SLIST));for(i=0;i<N;i++){q=(SLIST*)malloc(sizeof(SLIST));q->data=a[i];p->next=q;p=q;}returnh;}voidoutlist(SLIST{SLISTp=h-if(p==NULL)printf("\nThelistisNULL!\n");{do{printf("->%d",p->data);p=p->next;}while(p!=NULL);}}main({SLIST*head;intprintf("\nThelistbeforedeleting:\n");outlist(head);printf("\nThelistafterdeleting:\n");}funpqp指針,qpnextwhileqNULLq指針是NULL,NULLpqdata值是否相同,如果值相為止。如果兩個(gè)結(jié)點(diǎn)的值不相同,那么p就指向 指向q的next指針再繼續(xù)操作上述過刪除結(jié)點(diǎn)的方法是:先將p的next指針指向q的next指針,再q指針指向的內(nèi)存,最qpnext指針就可以刪除一個(gè)鏈表中的結(jié)點(diǎn)了。第一處:q指針?biāo)傅膬?nèi)存空間,應(yīng)填q。第二處:q指針指向p的next指針,重新完成,應(yīng)填nextqqnext指針,應(yīng)填nextMODI1.C中函數(shù)fun的功能是:n個(gè)元素按從小到main函數(shù),不得增行和刪行,也不得更改程序的結(jié)構(gòu)!#include<stdio.h>#defineN20voidfun(inta[],int{inti,j,t,for(j=0;j<n-1;j++)p=jfor(i=j;i<n;if(a[i]<p=j;t=a[p];a[p]=a[j];a[j]=}}{inta[N]={9,6,8,3,-1},i,m=printf("排序前的數(shù)據(jù)for(i=0;i<m;i++)printf("%d",a[i]);printf("\n");printf("排序后的數(shù)據(jù)for(i=0;i<m;i++)printf("%d",a[i]);}第二處:保存最小值的位置,所以應(yīng)改為:pi;fun1m之間(m)711整除的所有a中,通過nm50,則程序7111421222833354244注意:PROG1.Cmainfun的花括號(hào)中填入#includestdio.h>#defineM100voidfun(intm,int*a,int*n{}main({intaa[M],n,fun(50,aa,&nfor(k=0;k<n;k++)if((k+1)%20==0)printf("\n");elseprintf("%4d",aa[k]);printf("\n");NONO(}NONO({/**/FILE*fp,*wf;inti,n,j,k,aa[M],sumfp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%d,",&j);fun(j,aa,&n);sum=0for(k=0;k<n;k++)sum+=aa[k];fprintf(wf,"%d\n",sum);}fclose(fp);fclose(wf)}本題是考生對(duì)某個(gè)數(shù)能被其他的數(shù)整除方式,并把符合條件的數(shù)存放在數(shù)組a中。for循環(huán)語句以及取模的方式來解決這個(gè)問題的。#includestdio.h>#defineM100voidfun(intm,int*a,int*n{inti*n=0for(i=7;i<=m;if((i%7==0)||(i%11==0))a[(*n)++]=i}main({intaa[M],n,fun(50,aa,&nfor(k=0;k<n;k++)if((k+1)%20==0)printf("\n");elseprintf("%4d",aa[k]);printf("\n");NONO(}NONO({/**/FILE*fp,*wf;inti,n,j,k,aa[M],sumfp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%d,",&j);fun(j,aa,&n);sum=0for(k=0;k<n;k++)sum+=aa[k];fprintf(wf,"%d\n",sum);}fclose(fp);fclose(wf)}8套:給定程序中,函數(shù)fun的功能是:ch的結(jié)點(diǎn)。找到后通過函數(shù)值返回該結(jié)點(diǎn)在鏈表中所處的順序號(hào);若不存在ch0值。BLANK1.C中。#include<stdio.h>#includestdlib.h>#defineN8typedefstructlist{intdata;structlist*next;}SLIST*creatlist(char*);voidoutlist(SLIST*);intfun(SLIST*h,char{SLIST*p;intn=0; {if(p->data==ch)return elsep=p->next;}return}{SLIST*head;intk;charchara[N]={'m','p','g','a','w','x','r','d'};printf("Enteraletter:"); if(k==0)printf("\nNotelseprintf("Thesequencenumberis:}SLIST*creatlist(char{SLIST*h,*p,*q;inth=p=(SLIST*)malloc(sizeof(SLIST));for(i=0;i<N;i++){q=(SLIST*)malloc(sizeof(SLIST));q->data=a[i];p->next=q;p=q;}returnh;}voidoutlist(SLIST{SLISTp=h-if(p==NULL)printf("\nThelistisNULL!\n");{printf("\nHead");{printf("->%c",p->data);p=p->next;}}}應(yīng)填:returnnMODI1.C中函數(shù)fun的功能是:p所指字符串中的所有空白字符(包main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#include<string.h>#include<stdio.h>#include<ctype.h>fun(char*p){inti,t;charFor(i=0,t=0;p[i];i++)if(!isspace(*(p+i)))c[t++]=p[i];}main({charc,s[80];inti=0;printf("Inputastring:");{s[i]=c;i++;c=getchar();}}forForfunss所指字符串中所有下標(biāo)為奇數(shù)位置上例如,若輸入"abc4EFg",則應(yīng)輸出"aBc4EFg"。注意:PROG1.C中。mainfun的花括號(hào)中填入#include<stdio.h>#include<string.h>voidfunchar*ss{}main({chartt[81]printf("\nPleaseenteranstringwithin80characters:\n");gets(tt);printf("\n\nAfterchanging,thestring\n\"%s\"",tt);fun(ttprintf("\ es\n\"%s\"\n",tt);NONO();}NONO({/**/FILE*fp,*wf;chartt[81];inti;fp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%s",tt);fun(tt);fprintf(wf,"%s\n",tt)}fclose(fp);fclose(wf)}本題是考生對(duì)字母按要求進(jìn)行轉(zhuǎn)換。其中大小字母的ASCII值相差32。#include<stdio.h>#include<string.h>voidfun(char*ss{intifor(i=1;i<strlen(*ss);i+=2)if(ss[i]>='a'&&ss[i]<='z')ss[i]-=32}}main({chartt[81]printf("\nPleaseenteranstringwithin80characters:\n");gets(tt);printf("\n\nAfterchanging,thestring\n\"%s\"",tt);fun(ttprintf("\ es\n\"%s\"\n",tt);NONO();}NONO({/**/FILE*fp,*wf;chartt[81];inti;fp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%s",tt);fun(tt);fprintf(wf,"%s\n",tt)}fclose(fp);fclose(wf)}9套:給定程序中,fun的功能是:統(tǒng)計(jì)出帶有頭結(jié)點(diǎn)的單向鏈表中結(jié)點(diǎn)的個(gè)數(shù),存放在形參n所指的單元中。BLANK1.C中。#include<stdio.h>#includestdlib.h>#defineN8typedefstructlist{intdata;structlist*next;}SLIST*creatlist(int*a);voidoutlist(SLIST*);voidfun(SLIST*h,int{SLIST { }}{SLISTinta[N]={12,87,45,32,91,16,20,48}, ,&num);}SLIST*creatlist(int{SLIST*h,*p,*q;inth=p=(SLIST*)malloc(sizeof(SLIST));for(i=0;i<N;i++){q=(SLIST*)malloc(sizeof(SLIST));q->data=a[i];p->next=q;p=q;}returnh;}voidoutlist(SLIST{SLISTp=h-if(p==NULL)printf("ThelistisNULL!\n");{printf("\nHead");{printf("->%d",p->data);p=p->next;}}}第一處:對(duì)n所指的單元進(jìn)行初始化,所以應(yīng)填:*n。p的下一個(gè)結(jié)點(diǎn),所以應(yīng)填:next。**************************************************************給定程序OD1.C中函數(shù)funstNLL。例如,當(dāng)字符串中的內(nèi)容為:"abcdabfabcdx",t中的內(nèi)容為:"ab"時(shí),當(dāng)字符串中的內(nèi)容為:"abcdabfabcdx",t中的內(nèi)容為:"abd"時(shí),則程序輸出未找到信息:notbefound!。main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#include<stdio.h>#include<string.h>char*fun(char*s,char*t{char*p,*r,a=Null;while(*s){p=s;r=t;while(*r)if(r==p){r++;p++;elseif(*r=='\0')a=s;}returna}{chars[100],t[100],printf("\nPleaseenterstringS:");scanf("%s",s);printf("\nPleaseentersubstringt:");scanf("%s",t);p=fun(s,t);if(p)printf("\nTheresultis:%s\n",p);elseprintf("\nNotfound!\n");}funs所指字符串中除了下標(biāo)為偶數(shù)、同時(shí)ASCII值也為偶數(shù)的字符外,t所指的數(shù)組s所指字符串中的內(nèi)容為:"ABCDEFG123456"AASCII碼B的ASCII碼值為偶數(shù),但在數(shù)組中的下標(biāo)為2的ASCII碼值為偶數(shù),所在數(shù)組中的下標(biāo)也為偶t所指的數(shù)組中的內(nèi)容應(yīng)是:"246"。注意:PROG1.C中。main和其它函數(shù)中的任何內(nèi)容,fun的花括號(hào)中填入#include<stdio.h>#includestring.h>voidfun(char*s,char{}{chars[100],printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);}NONO({/**/chars[100],t[100];FILE*rf,*wf;inti;rf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%s",s);fun(s,t);fprintf(wf,"%s\n",t)}fclose(rf);fclose(wf)}本題是從一個(gè)字符串按要求生成另一個(gè)新的字符串。使用for循環(huán)語句來解決這個(gè)問#include<stdio.h>#includestring.h>voidfun(char*s,char{inti,j=0for(i=0;i<strlen(s);i+=2)if(s[i]%2==0)t[j++]=s[i];t[j]=0;}{chars[100],printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);}NONO({/*chars[100],t[100];FILE*rf,*wf;intirf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%s",s);fun(s,t);fprintf(wf,"%s\n",t)}fclose(rf);fclose(wf)}10套:給定程序中,函數(shù)fun的功能是:計(jì)算出帶有頭結(jié)點(diǎn)的單向鏈表中各結(jié)點(diǎn)數(shù)據(jù)BLANK1.C中。#include<stdio.h>#includestdlib.h>#defineN8typedefstructlist{intdata;structlist*next;}SLIST*creatlist(int*);voidoutlist(SLIST*);intfun(SLIST*h){SLIST*p;ints=0;{s+=p-> }return}{SLISTintprintf("\nsum=%d\n",fun( }SLIST*creatlist(int{SLIST*h,*p,*q;inth=p=(SLIST*)malloc(sizeof(SLIST));for(i=0;i<N;i++){q=(SLIST*)malloc(sizeof(SLIST));q->data=a[i];p->next=q;p=q;}returnh;}voidoutlist(SLIST{SLISTp=h-if(p==NULL)printf("ThelistisNULL!\n");{printf("\nHead");{printf("->%d",p->data);p=p->next;}}}**************************************************************給定程序OD1.C中函數(shù)fun將s12w處,要求1和2s所指字符串中的內(nèi)容為:"abcdabfab",t1所指子串中的內(nèi)容為:"ab",t2所指子串中的內(nèi)容為:"99"w所指的數(shù)組中的內(nèi)容應(yīng)為:main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#include#includeintfun(char*s,char*t1,char*t2,char{inti;char*p,*r,*a;strcpy(w,s);while(*w{p=w;r=while(r)if(*r==*p){r++;p++;}elsebreak;if(*r=='\0'{a=w;r=t2;while(*r){*a=*r;a++;}w+=strlen(t2)}else}}{chars[100],t1[100],t2[100],printf("\nPleaseenterstringS:");scanf("%s",s);printf("\nPleaseentersubstringt1:");scanf("%s",t1);printf("\nPleaseentersubstringt2:");scanf("%s",t2);if(strlen(t1)==strlen(t2)){fun(s,t1,t2,printf("\nTheresultis:%s\n",}elseprintf("Error:strlen(t1)!=}funs所指字符串中下標(biāo)為偶數(shù)的字符刪除,串中剩余字符t所指數(shù)組中。s所指字符串中的內(nèi)容為:"ABCDEFGHIJK",t所指數(shù)組中的內(nèi)容應(yīng)是:"BDFHJ"。注意:PROG1.C#include<stdio.h>#include<string.h>voidfun(char*s,char{}{chars[100],printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);}NONO({/**/chars[100],t[100];FILE*rf,*wf;inti;rf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%s",s);fun(s,t);fprintf(wf,"%s\n",t)}fclose(rf);fclose(wf)}本題是從一個(gè)字符串按要求生成另一個(gè)新的字符串。使用for循環(huán)語句來解決這個(gè)問#include<stdio.h>#includestring.h>voidfun(char*s,char{inti,j=0for(i=1;i<strlen(s);i+=2)t[j++]=s[i];t[j]=0;}{chars[100],printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);}NONO({/**/chars[100],t[100];FILE*rf,*wf;inti;rf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%s",s);fun(s,t);fprintf(wf,"%s\n",t)}fclose(rf);fclose(wf)}11套:結(jié)構(gòu)體數(shù)組std中,且唯一。函數(shù)fun的功能是:找出指定的數(shù)據(jù),作為函數(shù)值返回,由主函數(shù)輸出,若指定不存在,返回?cái)?shù)據(jù)中的為空串。BLANK1.C中。#include<stdio.h>#includestring.h>#defineN8typedefstruct{charintyear,month,day fun(STU*std,char{inti;STUfor(i=0;i<N;if(strcmp( ,num)==0)return( return}{STUstd[N]={STUp;charn[10]="666666";printf("\nNotfound!\n");{printf("\nSucceed!\n}}第二處:判斷結(jié)構(gòu)變量中的num是否相等,所以應(yīng)填:stu[i].num。第三處:返回相等的記錄值,所以應(yīng)填:std[i]。MODI1.C中函數(shù)funst所指字符main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#include<stdio.h>#include<string.h>intfun(char*s,char{intn;char*p,*r;n=0;while(*s{p=s;r=t;while(*r)if(*r==*p)r++;p++}elseif(r=='\0')}return}{chars[100],t[100];intprintf("\nPleaseenterstringS:");scanf("%s",s);printf("\nPleaseentersubstringt:");scanf("%s",t);m=fun(s,t);printf("\nTheresultis:m=%d\n",}t所指的數(shù)組中。s所指字符串中的內(nèi)容為:"ABCDEFG12345"BASCII碼值2ASCII,t所注意:PROG1.Cmainfun的花括號(hào)中填入#include<stdio.h>#includestring.h>voidfun(char*s,char{}{chars[100],printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);}NONO({/**/chars[100],t[100];FILE*rf,*wf;inti;rf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%s",s);fun(s,t);fprintf(wf,"%s\n",t)}fclose(rf);fclose(wf)}本題是從一個(gè)字符串按要求生成另一個(gè)新的字符串。使用for循環(huán)語句來解決這個(gè)問#include<stdio.h>#includestring.h>voidfun(char*s,char{inti,j=0for(i=0;i<strlen(s);i++)if(s[i]%2)t[j++]=s[i];t[j]=0;}{chars[100],printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);}NONO({/**/chars[100],t[100];FILE*rf,*wf;inti;rf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%s",s);fun(s,t);fprintf(wf,"%s\n",t)}fclose(rf);fclose(wf)}12套:結(jié)構(gòu)體數(shù)組std中。函數(shù)fun的功能是:找出指定出生年份的,將其數(shù)據(jù)放在k所指的數(shù)組中,由主函數(shù)輸出,同時(shí)由函數(shù)值返回滿足指定條件的人數(shù)。BLANK1.C中。#includestdio.h>#defineN8typedefstruct{intintyear,month,dayintfun(STU*std,STU*k,int{intfor(i=0;i<N;if( k[n++]= return( }{STUstd[N]={STUk[N];intprintf("Enterayear:");scanf("%d",&year); wasbornin%d\n",year);{printf("\nThese swerebornin%d\n",year);for(i=0;i<n;i++)}}本題是從給定的數(shù)據(jù)中找出相同的記錄存入k中,并返回符合條件的人數(shù)。第一處:斷結(jié)構(gòu)變量中的year是否相等,所以應(yīng)填:std[i].year。k中,所以應(yīng)填:std[i]。MODI1.C的功能是:k(2≤k≤10000),打印它的所有質(zhì)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#includeIsPrime(intn);{inti,m;m=1;for(i=2;i<n;i++if!(n%i){m=0;break;}return(m);}main({intj,printf("\nPleaseenteranintegernumberbetween2and10000:");scanf("%d",&k);printf("\n\nTheprimefactor(s)of%dis(are):",k);for(j=2;j<=k;j++)if((!(k%j))&&(IsPrime(j)))printf("\n%4d",j);}已知學(xué)生的記錄由學(xué)號(hào)和學(xué)習(xí)成績構(gòu)成,Nafun,函數(shù)的功能是:找出成績最高的學(xué)生記錄,通過形參指針注意:PROG1.Cmain和其它函數(shù)中的任何內(nèi)容,fun的花括號(hào)中填入#include<stdio.h>#includestring.h>#defineN10typedefstructss{charnum[10];ints;}STU;fun(STUa[],STU*s){}main({STUa[N]={{"A06",90},{"A07",79},{"A08",61},{"A09",80},{"A10",71}},mintprintf("*****Theoriginaldatafor(i=0;i<N;i++)printf("No=%sMark=%d\n",a[i].num,a[i].s);fun(a,&m);printf("*****THERESULT*****\n");printf("Thetop:%s,%d\n",m.num,m.s);NONO();NONO(){/*FILE*rf,*wf;STUa[N],m;intirf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++)fscanf(rf,"%s%d",a[i].num,&a[i].s);fun(a,&m);fprintf(wf,"Thetop:%s,%d\n",m.num,m.s);fclose(rf);fclose(wf)}本題學(xué)生在一組記錄中找出最高分。使用for循環(huán)語句來解決這個(gè)問題。#include<stdio.h>#include<string.h>#defineN10typedefstructss{charnum[10];ints;}STU;fun(STUa[],STU*s){inti,max=a[0].s,j=0;for(i=1;i<N;i++)if(max<a[i].s){j=imax=a[i].s}*s=a[j]}main({STUa[N]={{"A06",90},{"A07",79},{"A08",61},{"A09",80},{"A10",71}},mintprintf("*****Theoriginaldatafor(i=0;i<N;i++)printf("No=%sMark=%d\n",a[i].num,a[i].s);fun(a,&m);printf("*****THERESULT*****\n");printf("Thetop:%s,%d\n",m.num,m.s);NONO();NONO(){/*FILE*rf,*wf;STUa[N],m;intirf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++)fscanf(rf,"%s%d",a[i].num,&a[i].s);fun(a,&m);fprintf(wf,"Thetop:%s,%d\n",m.num,m.s);fclose(rf);fclose(wf)}13套:3門課的成績。函數(shù)funa。BLANK1.C中。#includestdio.h>typedefstruct{intnum;charname[9];floatvoidshow(STU{intprintf("%d%s:",tt.num,);for(i=0;i<3;i++)}voidmodify( *ss,floata){intfor(i=0;i<3; }main({STUstd={1,"Zhanghua",76.5,78.0,82.0floatprintf("\nTheoriginalnumberandnameandscores:\n");printf("\nInputanumber:"); printf("\nAresultofmodifying:\n");}本題是利用結(jié)構(gòu)體學(xué)生記錄并由實(shí)參ss返回第二處:該學(xué)生的各科成績都乘以一個(gè)系數(shù)a,所以應(yīng)填:score[i]MODI1.C中函數(shù)funk!(k<13,所求階乘的值作為函數(shù)值返回。例如:若k=10,則應(yīng)輸出:3628800。main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!#include<stdio.h>longfun(intk){ifk>0return(k*fun(k-elseif(k=0)return}{intk=10;printf("%d!=%ld\n",k,fun(k));}程序定義了N×N的二維數(shù)組,并在主函數(shù)中自動(dòng)賦值。請編寫函數(shù)fun(inta[][Nintn)n。n3,a數(shù)組中的值為|197||397a|238|則返回主程序后a|698|456||1215注意:PROG1.Cmainfun的花括號(hào)中填入#include<stdio.h>#includestdlib.h>#defineN5intfun(inta[][N],intn{}main({inta[N][N],n,i,printf("*****Thearray*****\n");for(i=0;i<N;i++){for(j=0;j<N;j++{a[i][j]=rand()%10;printf("%4d",a[i][j]);}}don=rand()%10;while(n>=3);printf("n=%4d\n",n);fun(a,nprintf("*****THERESULT*****\n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%4d",a[i][j]);}NONO(NONO(){/**/FILE*rf,*wf;inti,j,n,a[5][5]rf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<5;i++)for(j=0;j<5;j++)fscanf(rf,"%d",&a[i][j]);fscanf(rf,"%d",&n);fun(a,n);for(i=0;i<5;i++)for(j=0;j<5;j++)fprintf(wf,"%4d",a[i][j]);fprintf(wf,"\n");}fclose(rf);fclose(wf)}n。#include<stdio.h>#include<stdlib.h>#defineN5intfun(inta[][N],intn{inti,for(i=0;i<N;i++)for(j=0;j<=i;j++)a[i][j]*=n;}main({inta[N][N],n,i,printf("*****Thearray*****\n");for(i=0;i<N;i++){for(j=0;j<N;j++{a[i][j]=rand()%10;printf("%4d",a[i][j]);}}don=rand()%10;while(n>=3);printf("n=%4d\n",n);fun(a,nprintf("*****THERESULT*****\n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%4d",a[i][j]}NONO(NONO(){/*FILE*rf,*wf;inti,j,n,a[5][5];rf=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<5;i++)for(j=0;j<5;j++)fscanf(rf,"%d",&a[i][j]);fscanf(rf,"%d",&n);fun(a,n);for(i=0;i<5;i++)for(j=0;j<5;j++)fprintf(wf,"%4d",a[i][j]);fprintf(wf,"\n");}fclose(rf);fclose(wf)}14套:給定程序中,函數(shù)fun的功能是:numBLANK1.C中。#includestdio.h>typedefstruct{intchar}void{

{temp=std[0];std[0]=std[1];std[1]=temp;}{temp=std[0];std[0]=std[2];std[2]=temp;}{temp=std[1];std[1]=std[2];std[2]=temp;} std[]={5,"Zhanghu",2,"WangLi",6,"LinMin"};inti; printf("\nTheresultis:\n");for(i=0;i<3;i++)}funstd變量,所以應(yīng)填:*std。temp是存放交換記錄的中間變量,所以應(yīng)填:。MODI1.C中函數(shù)fun的功能是:m(1≤m≤

溫馨提示

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

評(píng)論

0/150

提交評(píng)論