高分飄過2013年國二語言上機(jī)題庫必備完美版_第1頁
高分飄過2013年國二語言上機(jī)題庫必備完美版_第2頁
高分飄過2013年國二語言上機(jī)題庫必備完美版_第3頁
高分飄過2013年國二語言上機(jī)題庫必備完美版_第4頁
高分飄過2013年國二語言上機(jī)題庫必備完美版_第5頁
已閱讀5頁,還剩294頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

{inta=5;}{floata,b;}charc;在這里就了字符常量字符串常字常量是由一對單號括起來的個(gè)字符字符串常量是一對雙引號括起來的字符序列。C”實(shí)際上包含兩個(gè)字符:‘if(a=3)thenif(a==3){z=xy;{z=xy;if(a%3==0);I;本是如果3整除a,則I加1。但由于ifa%3==0)后多加了分號,則if語句到此結(jié)束,程序?qū)?zhí)行I語句,不論3是否整除a,I都將自動加1。for(I=0;I<5;Iinta,b;3 如輸入ab{casecasecasecase'D':printf("<60");case'A':printf("85~100{staticint}例子如:字符串中原有的內(nèi)容為:abcdefgfun(char{intfor(;s {t=*(si);*(si)=*(sn-1-i);*(sn-1-次 intfun(char*s,int{int for(j=i1;j {t=s;s=s[j];for()循環(huán)走到最后一個(gè)字符。此外,此題還要注意把首尾字符除unsignedfun(unsignedw{if(w>=10000)returnw000;if(w>=1000)returnw00;if(w>=100)returnw0;returnw;} 求余得出后位數(shù)這樣一層一層往小的判斷。#defineM#defineNvoidfun(inttt[M][N],int{inti, { #defineMvoidfun(intbb[],int*n,int{intfor(i=0;i<*n;i)if(bb!=y)bb[j]=bb;6、請編寫一個(gè)函數(shù)intfun(intx),它的功能是:判斷整數(shù)x是否是同構(gòu)數(shù)。若是intfun(int{intxx=x*x;if(xx==x//xx==x//xx0==x)return1;elsereturn #defineMintfun(char*ss,char{intnum=0;{if(*ss==c)num++;ss++;}8、請編寫函數(shù)fun,經(jīng)的功能是:求出到 之內(nèi)能被或 voidfun(int*a,int{inti,m=0;for(i=1;i<1000;i){a[m]=i;m}#defineVSIZE20intintfun(intlist[],int inti,j=0;if(list[i]<list[j])j=i;returnj;}一.語法錯(cuò)誤④表達(dá)式錯(cuò)誤,如少了⑥函數(shù)形參類型錯(cuò)誤,如少*二.邏輯錯(cuò)誤(語義錯(cuò)誤百套試百套試 第01原來從到低位的順序組成一個(gè)新的數(shù),并通過形參指針n傳回所指變量。 ,新的數(shù):為739。0#include<stdio.h>voidfun(unsignedlong{unsignedlongx=0,i;intt;{t=*n%1;if(t%2!=2{x=x+t*i;i=i*10;*n=*n}*n=3}{unsignedlongn=-1; {printf("Pleaseinput(0<n< ):");scanf("%ld",&n);}printf("\nTheresultis:}給定程序MODI1.C中函數(shù)fun的功能是:計(jì)算ndoublefun(intn{doubleresult=1.0;ifn==0return1.0while(n>1&&n<170)result*=n--returnresult}main({intn;printf("InputN:")scanf("%d",&n)printf("\n\n%d!=%lf\n\n",n,fun(n))}第一處:條件語句書寫格式錯(cuò)誤,應(yīng)改為:if(n==0)。的將字符串轉(zhuǎn)換為整數(shù)的函數(shù))。例如,若輸入字符串"-1234",則函數(shù)把它轉(zhuǎn)換為整數(shù)值-1234。函數(shù)fun中給出的語句參考。0#include<stdio.h>#include<string.h>longfun(char*p){intilent*len為串長,t為正負(fù)標(biāo)識*/longx=0;{t=-1;len--;p++;else/*以下完成數(shù)字字符串轉(zhuǎn)換為一個(gè)數(shù)字*/returnx*t;}main(*主函數(shù){chars[6];longn;printf("Enterastring:\n");n=fun(s);NONO();}NONO({/*本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*fp,*wf;intichars[20];longn;fp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%s",s);n=fun(s);fprintf(wf,"%ld\n",n)}fclose(fp);fclose(wf)}#include<stdio.h>#include<string.h>longfun(char*p){intilent*len為串長,t為正負(fù)標(biāo)識*/longx=0;{t=-1;len--;p++;else/*以下完成數(shù)字字符串轉(zhuǎn)換為一個(gè)數(shù)字*/while(*p)x=x*10-48+(*p++);return}main(*主函數(shù){chars[6];longn;printf("Enterastring:\n");n=fun(s);NONO();}NONO({/*本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*fp,*wf;intichars[20];longn;fp=fopen("c:\\test\\in.dat","r");wf=fopen("c:\\test\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%s",s);n=fun(s);fprintf(wf,"%ld\n",n)}fclose(fp);fclose(wf)}始均省略NONO()第02給定程序中,函數(shù)fun的功能是將形參給定的字符串、整數(shù)、浮點(diǎn)數(shù)寫到文本文件中,再用#includevoidfun(char*s,inta,double{1fp;charfp=fopen("file1.txt",fprintf(fp,"%s%d%f\n",s,a,f);fp=fopen("file1.txt","r");printf("\nTheresult:\n\n");ch=fgetc(fp);while(!feof(2))putchar(3);ch=fgetc(fp);}}{chara[10]=" o!";intb=12345;doublec=98.76;}第一處:定義文本文件類型變量,所以應(yīng)填:FILE*。給定程序MODI1.C中函數(shù)fun的功能是:依次取出字符串中所有數(shù)字字符,形成新的字符串,并取代原字符串。voidfun(char*s){intfor(i=0,j=0;s[i]!='\0';if(s[i]>='0'&&s[i]<='9')s[j]=s[i];}{charprintf("\nEnterastring:");gets(item);printf("\n\nThestringis:\"%s\"\n",item);printf("\n\nThestringofchangingis:\"%s\"\n",item}第一處:要求是取出原字符串中所有數(shù)字字符組成一個(gè)新的字符串,程序中是使用變量j來控制新字符串的位置,所以應(yīng)改為:sj++]=s[i];。第二處:置新字符串的結(jié)束符,所以應(yīng)改為:s請編寫函數(shù)fun,函數(shù)的功能是:將M行N列的二維數(shù)組中的字符數(shù)據(jù),按列的WWWWSSSSHHHWSHWSHWSH。#include<stdio.h>#defineM#defineNvoidfun(chars[][N],char{intfor(i=0;iN;i*請?zhí)顚懴鄳?yīng)語句完成其功能{}{charintfor(i=0;i<M;i++){for(j=0;j<N;j++)printf("%3c",w[i][j]);}printf("TheAstring:\n");puts(a);}voidfun(chars[][N],char{intfor(i=0;iN;i*請?zhí)顚懴鄳?yīng)語句完成其功能{for(j=0;j<M;j++){b[n]=s[j][i];n=i*M+j+}}以二進(jìn)制方式輸出到文件中。函數(shù)fun的功能是重寫形參filename所指文件中最后一個(gè)學(xué)生的數(shù)據(jù),即用新的學(xué)生數(shù)據(jù)覆蓋該學(xué)生原來的數(shù)據(jù),其它學(xué)生的數(shù)據(jù)不變。#defineN5typedefstructstudentlongcharname[10];floatscore[3];}voidfun(char*filename,STU{FILEfp=fopen(1,fseek(2,-1L*sizeof(STU),SEEK_END);fwrite(&n,sizeof(STU),1,3);}{STUt[N]={{10001,"MaChao",91,92,77},{10002,"CaoKai",75,60,{10003,"LiSi",85,70,78},{10004,"FangFang",90,82,{10005,"ZhangSan",95,80,STUn={10006,"ZhaoSi",55,70,68},inti,j;FILEfp=fopen("student.dat","wb");fwrite(t,sizeof(STU),N,fp);fp=fopen("student.dat","rb");fread(ss,sizeof(STU),N,fp);printf("\nTheoriginaldata:\n\n");for(j=0;j<N;j++){printf("\nNo:%ldName:%-8sScores:",ss[j].sno,ss[for(i=0;i<3;i++)printf("%6.2f",ss[j].score[i]);}printf("\nThedataaftermodifing:\n\n");fp=fopen("student.dat","rb");fread(ss,sizeof(STU),N,fp);for(j=0;j<N;{printf("\nNo:%ldName:%-8sScores:",ss[j].sno,ss[for(i=0;i<3;i++)printf("%6.2f",ss[j].score[i]);}}給定程序MODI1.C中的函數(shù)Creatlink的功能是創(chuàng)建結(jié)點(diǎn)的單向鏈表,并為各結(jié)點(diǎn)數(shù)#include<stdio.h>#include<stdlib.h>typedefstructaa{intdata;structaa}NODE*Creatlink(intn,int{NODE*h=NULL,*p,*s;inti;for(i=1;i<=n;i++){s=(NODEs->data=rand()%m;s->next=p->next;p->next=s;p=p->next;}return}outlink(NODE{NODEprintf("\n\nTHELIST:\n\nHEAD");{printf("->%d",p->data);}}{NODE*head;}第一處:指向剛分配的結(jié)構(gòu)指針,所以應(yīng)改為:p=(NODEh保存p指針的初始位置,請編寫函數(shù)fun,函數(shù)的功能是:統(tǒng)計(jì)一行字符串中單詞的個(gè)數(shù),作為函數(shù)值返回。一行字符串在主函數(shù)中輸入,規(guī)定所有單詞由小寫字母組成,單詞之間由若干個(gè)空格隔開,一行的開#include<stdio.h>#include<string.h>#defineN80intfun(char{}{charline[N];intnum=0;printf("Enterastring:\n");gets(line);num=fun(line);printf("Thenumberofwordis:%d\n\n",num);}intfun(char{intk=1;while(*s)if(*s=='')k++;s++;}returnk}#defineN5typedefstructstudent{longsno;charname[10];floatscore[3];}voidfun(char{FILE*fp;inti,j;STUs[N],t;fp=fopen(filename,1);fread(s,sizeof(STU),N,fp);for(i=0;i<N-1;i++)for(j=i+1;j<N;if(s[i].sno2s[{t=s[i];s[i]=s[j];s[j]=t;}fp=fopen(filename,"wb");3(ssizeof(STU)Nfp)*二進(jìn)制輸出*/}{STUt[N]={{10005,"ZhangSan",95,80,88},{10003,"LiSi",85,70,{10002,"CaoKai",75,60,88},{10004,"FangFang",90,82,{10001,"MaChao",91,92,77}},inti,j;FILEfp=fopen("student.dat","wb");fwrite(t,sizeof(STU),5,fp);printf("\n\nTheoriginaldata:\n\n");for(j=0;j<N;j++){printf("\nNo:%ldName:%-8sScores:",t[j].sno,t[for(i=0;i<3;i++)printf("%6.2f",t[j].score[i]);}printf("\n\nThedataaftersorting:\n\n");fp=fopen("student.dat","rb");fread(ss,sizeof(STU),5,fp);for(j=0;j<N;{printf("\nNo:%ldName:%-8sScores:",ss[j].sno,ss[for(i=0;i<3;i++)printf("%6.2f",ss[j].score[i]);}}給定程序MODI1.C中函數(shù)fun的功能是:在字符串的最前端加入n個(gè)*號,形成新串,并且覆注意:字符串的長度最長允許為79#include<stdio.h>#include<string.h>voidfun(chars[],intn){chara[80],*p;inti;for(i=0;i<n;i++)a[i]='*';{a[i]=*p;}}{intn;charprintf("\nEnterastring:");gets(s);printf("\nThestring\"%s\"\n",s);printf("\nEntern(numberof*):");scanf("%d",&n);printf("\nThestringafterinsert:\"%s\"\n"}第一處:指針p應(yīng)指向s,所以應(yīng)改為:p=s第二處:死循環(huán),當(dāng)dowhile循環(huán)執(zhí)行一次,臨時(shí)變量p應(yīng)該指向字符串的下一位置,所以其余依此類推,把100歲(含100)以上的人數(shù)都放在d[10]中。結(jié)果在主函數(shù)中輸出#defineN50#defineMvoidfun(int*a,int{}double{statict=29,c=217,m=1024,r=0;r=(r*t+c)%m;return((double)r/m);}{intage[N],i,for(i=0;i<N;i++)age[i]=(int)(115*rnd());printf("Theoriginaldata:\n");fun(age,for(i=0;i<10;i++)printf("%4d---%4d:%4d\n",i*10,i*10+9,d[i]);printf("Over100:%4d\n",d[10]);}voidfun(int*a,int{inti,jfor(i=0;i<M;i++)b[i]=0;for(i=0;i<N;i++){j=a[i]/10if(j>10)b[M-1]++;elseb[j]++}}double{statict=29,c=217,m=1024,r=0;r=(r*t+c)%m;return((double)r/m);}#include<stdio.h>#include<stdlib.h>voidfun(char*s,inta,double{1charstr[100],str1[100],str2[100];inta1;doublef1;fp=fopen("file1.txt",fprintf(fp,"%s%d%f\n",s,a,2fp=fopen("file1.txt",fscanf(3,"%s%s%s",str,str1,str2);a1=atoi(str1);f1=printf("\nTheresult:\n\n%s%d%f\n",str,a1,}{chara[10]=" o!";intb=12345;doublec=98.76;}}}給定程序MODI1.C中函數(shù)fun的功能是:對N名學(xué)生的學(xué)習(xí)成績,按從高到低的順序找出前m(m≤10)名學(xué)生來,并將這些學(xué)生數(shù)據(jù)存放在一個(gè)動態(tài)分配的連續(xù)區(qū)中,此區(qū)的#include<stdio.h>#include<alloc.h>#include<string.h>#defineN10typedefstructss{charnum[10];ints;}STU*fun(STUa[],int{STUb[N],intfor(i=0;i<N;i++)b[i]=a[i];for(k=0;k<m;k++){for(i=j=0;i<N;i++)if(b[i].s>b[j].s)j=i;t(k)=b(j);}return}outresult(STUa[],FILE{intfor(i=0;i<N;fprintf(pf,"No=%sMark=%d\n",a[i].num,a[i].s);{STUa[N]={STU*pOrder;inti,m;printf("*****TheOriginaldata*****\n");outresult(a,stdout);printf("\nGivethenumberofthestudentswhohavebetterscore:");while(m>10{printf("\nGivethenumberofthestudentswhohavebetterscore:");}printf("*****THERESULT*****\n");printf("Thetop:\n");for(i=0;i<m;printf("%s%d\n",pOrder[i].num,pOrder[i].s);}第二處:應(yīng)該使用方括號,而不是圓括號。請編寫函數(shù)fun,函數(shù)的功能是:刪去一維數(shù)組中所有相同的數(shù),使之只剩一個(gè)。數(shù)組中的22234456666778991010102345678910。#include<stdio.h>#defineNintfun(inta[],int{{intprintf("Theoriginaldata:\n");for(i=0;i<n;i++)printf("%3d",a[i]);printf("\n\nThedataafterdeleted:\n");}intfun(inta[],int{inti,j=1,k=a[0];for(i=1;i<n;i++)if(k!=a[i]){a[j++]=a[i];k=a[i];}a[j]=0returnj}fun的功能是根據(jù)形參ix1=5.000000,x2=3.000000,#include<stdio.h>doublef1(doublex){returnx*x;doublef2(doublex,double{returnx*y;1fun(inti,doublex,double{if(i==1)return2(x);return3(x,}{doublex1=5,x2=3,r;r=fun(1,x1,x2);r+=fun(2,x1,}給定程序MODI1.C中函數(shù)fun#includecharfun(char*s,char{intsl=0,tl=0;char*ss,*tt;ss=s;tt=t;{sl++;}{tl++;}if(tl>sl)returnt;elsereturns;}{chara[80],b[80],*p,*q;inti;printf("\nEnterastring:");gets(a);printf("\nEnterastringagain:");gets(b);printf("\nThelongeris:\n\n\"%s\"\n",fun(a,b));}第一處:試題要求返回字符串的首地址,所以應(yīng)改為:char*fun(char*s,char第二處:取字符串指針ss的下一個(gè)位置,所以應(yīng)改為:ss++;。請編寫函數(shù)fun,函數(shù)的功能是:移動字符串中的內(nèi)容,移動的規(guī)則如下:把第1到第m個(gè)字符,平移到字符串的最后,把第m+1到最后的字符移到字符串的前部。例如,字符串中原有的內(nèi)容為:ABCDEFGHIJK,m的值為3,則移動后,字符串中的內(nèi)容應(yīng)該是:DEFGHIJKABC。#include<stdio.h>#include<string.h>#defineN80voidfun1(char*w*本函數(shù)的功能是將字符串中字符循環(huán)左移一個(gè)位置{inti;chart;}voidfun(char*wintm)*可調(diào)用fun1函數(shù)左移字符{}{chara[N]=intprintf("Theoriginalstring:\n");puts(a);printf("\n\nEnterm:");scanf("%d",&m);printf("\nThestringaftermoving:\n");puts(a);}voidfun1(char*w*本函數(shù)的功能是將字符串中字符循環(huán)左移一個(gè)位置{inti;chart;}voidfun(char*wintm)*可調(diào)用fun1函數(shù)左移字符{intfor(i=0;i<m;i++)}typedefstruct{intnum;charname[9]; struct{intyear,month,day;}birthday;floatscore[3];voidshow(STU {intprintf("\n%d%s%c%d-%d-%d",tt.num,,tt. tt.birthday.year,tt.birthday.month,tt.birthday.day);for(i=0;i<3;i++)printf("%5.1f", }main({STUstd={1,"Zhanghua",'M',1961,10,8,76.5,78.0,82.0printf("\nAstudentdata:\n"); }給定程序MODI1.C中函數(shù)fun#include<stdio.h>#defineNintfun(int*a,intn{inti,m,t,k;for(i=0;i<2;i++){if(a[k]>a[m])k=m;}}main({intx,b[N]={11,5,12,0,3,6,9,7,10,8},n=10,for(i=0;i<n;i++)printf("%d",b[i]);fun(b,nfor(i=0;i<n;i++)printf("%d",b[i]);}])請編寫一個(gè)函數(shù)unsignedfun(unsignedw),w是一個(gè)大于10的無符號整數(shù),若是nn≥2)位的整數(shù),函數(shù)求出w的低n-1例如:w值為5923,則函數(shù)返回923;w值為923則函數(shù)返回23。#include<stdio.h>unsignedfun(unsignedw{}main({unsignedprintf("Enteraunsignedintegernumber:");scanf("%u",&x);printf("Theoriginaldatais:%u\n",x);if(x<10)printf("Dataerrorelseprintf("Theresult:%u\n",fun(x));NONO();}unsignedfun(unsignedw{if(w>10000)w%=10000elseif(w>1000)w%=1000;elseif(w>100)w%=100;elseif(w>10)w%=10;returnw;}typedefstruct{intnum;charname[9];floatvoidshow(STU{intprintf("%d%s:",tt.num,);for(i=0;i<3;i++)}void *ss,float{intfor(i=0;i<3;i++) }main({STUstd={1,"Zhanghua",76.5,78.0,82.0floatprintf("\nTheoriginalnumberandnameandscores:\n");printf("\nInputanumber:");scanf("%f",&a); printf("\nAresultofmodifying:\n");}k(k<13如:若k=10,則應(yīng)輸出: longfun(intk){ifk>elseif(k=0)return}{intk=10;printf("%d!=%ld\n",k,fun(k));}程序定義了N×Nfun(inta[][Nintn),函數(shù)的功能是:使數(shù)組左下三角元素中的值乘以n。例如:若n的值為3,a數(shù)組中的值為|197||397a|238|則返回主程序后a數(shù)組中的值應(yīng)為|698|456||121518|#include<stdio.h>#include<stdlib.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(}intfun(inta[][N],intn{inti,for(i=0;i<N;i++)for(j=0;j<=i;j++)a[i][j]*=n;}#include<stdio.h>#include<stdlib.h>#defineN6typedefstructnode{intdata;structnode}voidfun(NODE{NODE*p,*q;intt;p=h;while(p){q=1while(2{if(p->data>q-{t=p->data;p->data=q->data;q->data=t;}q=q->next;}p=3}}{NODE*h,*p,*q;inti;for(i=0;i<N;{q=(NODE*)malloc(sizeof(NODE));q->next=if(h==NULL)h=p=q;else{p->next=q;p=q;}}return}voidoutlist(NODE{NODEif(p==NULL)printf("ThelistisNULL!\n");{printf("\nHead");{printf("->%d",p->data);p=p->next;}}}{NODEinta[N]={0,10,4,2,8,6printf("\nTheoriginallist:\n");printf("\nThelistafterinverting:\n");}給定程序MODI1.C中函數(shù)fun的功能是:將s所指字符串中的字母轉(zhuǎn)換為按字母序列的后續(xù)字母(但Z轉(zhuǎn)換為A,z轉(zhuǎn)換為a),其它字符不變。#include<stdio.h>#include<ctype.h>voidfun(char*s){{if(*s>='A'&*s<='Z'||*s>='a'&&{if(*s=='Z')elseif(*s=='z')*s='a';else*s+=1;}}{charprintf("\nEnterastringwithlength<80.:\n\n");gets(s);printf("\nThestring:\n\n");puts(s);fun(sprintf("\n\nTheCords:\n\n");}第一處:使用while循環(huán)來判斷字符串指針s是否結(jié)束,所以應(yīng)改為:while(*s)。第二處:取字符串指針s的下一個(gè)位置,所以應(yīng)改為:s++;。請編寫函數(shù)fun,函數(shù)的功能是:移動一維數(shù)組中的內(nèi)容;若數(shù)組中有n個(gè)整數(shù),要求把下標(biāo)1,2,3,4,5,6,7,8,9,10p的值為3。移動后,一維數(shù)組中的內(nèi)容應(yīng)為:5,6,7,8,9,10,1,2,3,4。#defineN80voidfun(int*w,intp,int{}{intintprintf("Theoriginaldata:\n");for(i=0;i<n;i++)printf("%3d",a[i]);printf("\n\nEnterp:");scanf("%d",&p);printf("\nThedataaftermoving:\n");for(i=0;i<n;i++)printf("%3d",a[i]);}voidfun(int*w,intp,int{inti,j=0,b[N]for(i=p+1;i<n;i++)b[j++]=w[i];for(i=0;i<=p;i++)b[j++]=w[i];for(i=0;i<n;i++)w[i]=b[i]}493581#defineN3intfun(int{inti,j,m1,m2,row,colum;for(i=0;i<N;{j=N-i-1;m1+=a[i][i];m2+=a[i][j];if(m1!=m2)return0;for(i=0;i<N;i++){row=colum=1;for(j=0;j<N;j++){row+=a[i][j];colum+=a[j][i];if((row!=colum)2(row!=m1))return}return3}{intprintf("Enternumberforarray:\n");for(i=0;i<N;i++)for(j=0;j<N;j++)scanf("%d",&x[i][j]);for(i=0;i<N;{for(j=0;j<N;j++)printf("%3d",x[i][j]);}if(fun(x))printf("TheArrayisamagicsquare.\n");elseprintf("TheArrayisn'tamagicsquare.\n");}給定程序MODI1.C中fun函數(shù)的功能是:根據(jù)整型形參m,計(jì)算如下的值 t=1 -…… 例如,若主函數(shù)中輸入5,則應(yīng)輸出-0.283333。#include<stdio.h>doublefun(intm{doublet=1.0;inti;for(i=2;i<=m;i++)t=1.0-1/i; }{intmprintf("\nPleaseenter1integernumbers:\n");scanf("%d",&m);printf("\n\nTheresultis%lf\n",fun(m)}例如,主函數(shù)中輸入"asdafaaz67",則輸出為"asdafaaz67"。#include<stdio.h>#include<ctype.h>intfun(char*str){}{charstr[81];intn;printf("Inputastring:");printf("***str:%s\n",str);}intfun(char{char*p=str;inti=0;while(*p){if(*p!='')str[i++]=*p;p++;}str[i]=0}#include<stdio.h>#includestdlib.h>#defineN5typedefstructnode{intdata;structnode}voidfun(NODE{NODE*p,*q,/p=h->1/if(p==2)return;q=p->next;p->next=NULL;while(q){r=q->next;q->next=p;p=q;q=3;}h->next=}{NODE*h,*p,*q;inth=(NODE*)malloc(sizeof(NODE));h->next=NULL;for(i=0;i<N;{q=(NODE*)malloc(sizeof(NODE));q->next=if(h->next==NULL)h->next=p=q;else{p->next=q;p=q;}}return}voidoutlist(NODE{NODEp=h-if(p==NULL)printf("ThelistisNULL!\n");{printf("\nHead{printf("->%d",p->data);p=p->next;}}}{NODEintprintf("\nTheoriginallist:\n");printf("\nThelistafterinverting:\n");}給定程序MODI1.C中函數(shù)fun的功能是:計(jì)算s所指字符串中含有t所指字符串的數(shù)目,并作#include<stdio.h>#include<string.h>#defineN80intfun(char*s,char{intchar*p,*r;while(*s{if(*r==*p){r++;p++;}elsebreak;if(*r=0)}return}{chara[N],b[N];intprintf("\nPleaseenterstringa:");gets(a);printf("\nPleaseentersubstringb:");gets(b);m=fun(a,b);printf("\nTheresultis:m=}第一處:程序中子串是由變量twhile第二處:是判斷相等的條件,所以應(yīng)改為:if(*r==0請編寫函數(shù)fun,函數(shù)的功能是:將放在字符串?dāng)?shù)組中的M個(gè)字符串(每串的長度不超過N),例如,字符串?dāng)?shù)組中的M#defineM3#defineNvoidfun(chara[M][N],char{inti;}{charw[M][N]={"AAAA","BBBBBBB","CC"},intiprintf("Thestring:\n");for(i=0;i<M;i++)puts(w[i]);printf("TheAstring:\n");}voidfun(chara[M][N],char{inti;for(i=0;i<M;i++)strcat(b,a[i]);}#include<stdio.h>#include<stdlib.h>#defineN5typedefstructnode{intdata;structnode}1*fun(NODE{NODE*p,*q,*r;p=h;if(p==returnNULL;q=p-p->next=NULL;while(q){r=q->2;q->next=p=q=3}return}{NODE*h,*p,*q;inti;for(i=0;i<N;{q=(NODE*)malloc(sizeof(NODE));q->next=if(h==NULL)h=p=q;else{p->next=q;p=q;}}return}voidoutlist(NODE{NODEif(p==NULL)printf("ThelistisNULL!\n");{printf("\nHead");{printf("->%d",p->data);p=p->next;}}}{NODEintprintf("\nTheoriginallist:\n");printf("\nThelistafterinverting:\n");}第一處:由于鏈表中的所有結(jié)果要求通過函數(shù)進(jìn)行返回,所以應(yīng)填:NODE*。給定程序MODI1.C中函數(shù)fun的功能是:將s所指字符串中位于奇數(shù)位置的字符或ASCII碼例如,字符串中的數(shù)據(jù)為:#include<stdio.h>#include<string.h>#defineN80voidfun(char*s,char{inti,for(i=0;i<strlen(s);i++)if(i%2&&s[i]%2==0)t[j++]=s[i];}{chars[N],printf("\nPleaseenterstrings:");fun(s,printf("\nTheresultis:}改為:if(i%2||s[i]%2==0)。t的位置是由i來控制,所以應(yīng)改為:tj]=0;。請編寫函數(shù)fun,函數(shù)的功能是:將M行N列的二維數(shù)組中的數(shù)據(jù),按列的順序333333444444555555334455334455334455334455#includevoidfun(ints[][10],intb[],int*n,intmm,int{inti,j,np=0;*np用作b數(shù)組下標(biāo)}{intw[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j;inta[100]={0},n=0;for(i=0;i<3;i++){for(j=0;j<4;j++)printf("%3d",w[i][j]);}printf("TheAarray:\n");}voidfun(int(*s)[10],int*b,int*n,intmm,int{inti,j,np=0;*np用作b數(shù)組下標(biāo)*/for(i=0;i<nn;i++)for(j=0;j<mm;j++){b[np]=s[j][i];np=i*mm+j+}}#include<stdio.h>#include<stdlib.h>#defineN6typedefstructnode{intdata;structnode}voidfun(NODE{NODE*p,*q;intt;p=1;while(p){q=2;while(q){if(p->data3q-{t=p->data;p->data=q->data;q->data=t;}q=q->next;}p=p-}}{NODE*h,*p,*q;inth=(NODE*)malloc(sizeof(NODE));h->next=NULL;for(i=0;i<N;{q=(NODE*)malloc(sizeof(NODE));q->next=if(h->next==NULL)h->next=p=q;else{p->next=q;p=q;}}return}voidoutlist(NODE{NODEp=h-if(p==NULL)printf("ThelistisNULL!\n");{printf("\nHead");{printf("->%d",p->data);p=p->next;}}}{NODEinta[N]={0,10,4,2,8,6printf("\nTheoriginallist:\n");printf("\nThelistaftersorting:\n");}或>=給定程序MODI1.C是建立一個(gè)結(jié)點(diǎn)的單向鏈表,并用隨機(jī)函數(shù)為各結(jié)點(diǎn)數(shù)據(jù)域賦值。函數(shù)fun的作用是求出單向鏈表結(jié)點(diǎn)(不包括頭結(jié)點(diǎn))數(shù)據(jù)域中的最大值,并且作為函數(shù)值返#include<stdio.h>#include<stdlib.h>typedefstructaa{intdata;structaa}fun(NODE*h{intmax=-1;NODE*p;p=h;{if(p->data>max)p=h->next;}return}outresult(ints,FILE{fprintf(pf,"\nThemaxinlink:%d\n",s);}NODE*creatlink(intn,intm){NODE*h,*p,*s,*q;inti,x;h=p=(NODE*)malloc(sizeof(NODE));h->data=9999;for(i=1;i<=n;i++){s=(NODEs->data=rand()%m;s->next=p->next;p->next=s;p=p->next;}returnh;}outlink(NODE*h,FILE{NODEfprintf(pf,"\nTHELIST:\n\nHEAD");{fprintf(pf,"->%d",p->data);p=p->next;}}{NODE*head;intm;head=creatlink(12,100);outlink(head,stdout);printf("\nTHERESULT:\n");outresult(m,}p指向形參結(jié)構(gòu)指針h的next指針,所以應(yīng)改為:p=h->next;。第二處:p指向自己的下一個(gè)結(jié)點(diǎn),所以應(yīng)改為:p=p->next,請編寫函數(shù)fun,函數(shù)的功能是:將M行N列的二維數(shù)組中的數(shù)據(jù),按行的順序依次放到一維數(shù)組中,一維數(shù)組中數(shù)據(jù)的個(gè)數(shù)存放在形參n所指的單元中。例如,二維數(shù)組中的數(shù)據(jù)為:33333333444444555555333333334444444455555555#includevoidfun(int(*s)[10],int*b,int*n,intmm,int{}{intw[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j;inta[100]={0},n=0;printf("Thematrix:\n");for(i=0;i<3;i++){for(j=0;j<4;j++)printf("%3d",w[i][j]);printf("\n");}fun(w,a,&n,3,4);printf("TheAarray:\n");for(i=0;i<n;i++)printf("%3d",a[i]);printf("\n\n");NONO();}voidfun(int(*s)[10],int*b,int*n,intmm,int{inti,j,kfor(i=0;i<mm;i++)for(j=0;j<nn;j++){k=i*nn+j;b[k]=s[i][j]}*n=mm*nn}給定程序中,函數(shù)fun規(guī)定在2處使f指向函數(shù)f1,在3處使f指向函數(shù)f2。當(dāng)調(diào)用正確時(shí),程序輸出:x1=5.000000,x2=3.000000,x1*x1+x1*x2=40.000000#include<stdio.h>doublef1(doublex){returnx*x;doublef2(doublex,double{returnx*y;doublefun(doublea,double{1(*f)();doubler1,r2;f=2;/*pointfountionf1*/r1=f(a);f=3;/*pointfountionf2*/r2=(*f)(a,b);returnr1+}{doublex1=5,x2=3,r;r=fun(x1,x2);}的功能是將單向鏈表結(jié)點(diǎn)(不包括頭結(jié)點(diǎn))數(shù)據(jù)域?yàn)榕紨?shù)的值累加起來,并且作為函數(shù)值返#include<stdio.h>#include<stdlib.h>typedefstructaa{intdata;structaa*next;}NODE;intfun(NODE*h){intsum=0;NODE*p;{if(p->data%2==0)sum+=p->data;}return}{NODE*h,*p,*s,*q;inti,x;for(i=1;i<=n;i++){s=(NODE*)malloc(sizeof(NODE));}returnh;}outlink(NODE*h,FILE{NODEp=h-fprintf(pf,"\n\nTHELIST:\n\nHEAD");{fprintf(pf,"->%d",p->data);p=p->next;}fprintf(pf,"\n");}outresult(ints,FILE{fprintf(pf,"\nThesumofevennumbers:{NODE*head;inteven;outlink(head,stdout);printf("\nTheresult:\n");outresult(even,}請編寫函數(shù)fun,函數(shù)的功能是:判斷字符串是否為回文?若是,函數(shù)返回1,YES,否則返回0,主函數(shù)中輸出NO。回文是指順讀和倒讀都一樣的字符串。例如,字符串LEVEL是回文,而字符串123312就不是回文。#defineN80intfun(char{}{chars[N]printf("Enterastring:");gets(s);printf("\n\n");puts(s);if(fun(s))printf("YES\n");elseprintf("NO\n");NONO();}intfun(char{inti,j=strlen(str);for(i=0;i<j/2;i++)if(str[i]!=str[j-i-1])return0;return1;}程序通過定義學(xué)生結(jié)構(gòu)體變量,了學(xué)生的學(xué)號、和3門課的成績。所有學(xué)生數(shù)據(jù)均以二進(jìn)制方式輸出到student.datfun的功能是從指定文件中找出指定學(xué)號的學(xué)生數(shù)據(jù),讀入此學(xué)生數(shù)據(jù),對該生的分?jǐn)?shù)進(jìn)行修改,使每門課的分?jǐn)?shù)加3分,修改后重寫文件中該學(xué)生的數(shù)據(jù),即用該學(xué)生的新數(shù)據(jù)覆蓋原數(shù)據(jù),其它學(xué)生數(shù)據(jù)不變;若找不到,#defineN5typedefstructstudent{longsno;charname[10];floatscore[3];}voidfun(char*filename,long{FILE*fp;STUn;inti;fp=fopen(filename,"rb+");while(!feof(1)){fread(&n,sizeof(STU),1,fp);if(n.sno2sno)break;}if{for(i=0;i<3;i++)n.score[i]+=3;fseek(3,-1L*sizeof(STU),SEEK_CUR);fwrite(&n,sizeof(STU),1,fp);}}{STUt[N]={{10001,"MaChao",91,92,77},{10002,"CaoKai",75,60,{10003,"LiSi",85,70,78},{10004,"FangFang",90,82,{10005,"ZhangSan",95,80,88}},inti,j;FILEfp=fopen("student.dat","wb");fwrite(t,sizeof(STU),N,fp);printf("\nTheoriginaldata:\n");fp=fopen("student.dat","rb");fread(ss,sizeof(STU),N,fp);for(j=0;j<N;{printf("\nNo:%ldName:%-8sScores:",ss[j].sno,ss[for(i=0;i<3;i++)printf("%6.2f",ss[j].score[i]);}fp=fopen("student.dat","rb");fread(ss,sizeof(STU),N,fp);printf("\nThedataaftermodifing:\n");for(j=0;j<N;j++){printf("\nNo:%ldName:%-8sScores:",ss[j].sno,ss[for(i=0;i<3;i++)printf("%6.2f",ss[j].score[i]);}}個(gè)字符插入到前兩個(gè)字符中,插入后前三個(gè)字符依然有序;再把第符插入到前三個(gè)#include#include<string.h>#defineN80voidinsert(char{inti,j,n;charch;n=strlen[aa];for(i=1;i<n;i++){while((j>=0)&&(ch<aa[j]{aa[j+1]=aa[j];}}}main({charintiprintf("Theoriginalstring:%s\n",a);insert(a);printf("Thestringaftersorting:%s\n\n",a}第一處:函數(shù)應(yīng)該使用圓括號,所以應(yīng)改為:n=strlen(aa第二處:變量c沒有定義,但后面使用的是ch變量,所以應(yīng)改為:ch=aa[i]#include<stdio.h>#include<stdlib.h>#defineN8struct{doubles;structslisttypedefstructslistSTREC;doublefun(STREC*h){}STREC*creat(double{STREC*h,*p,*q;inti=0;q->s=s[i];i++;p->next=q;p=q;}returnh;}outlist(STREC{STRECp=h->next;printf("head");{printf("->%2.0f",p->s);p=p->next;}}{doubles[N]={85,76,69,85,91,72,64,87},max;STREC*h;h=creat(s);outlist(h);max=fun(h);}doublefun(STREC*h{doublemax=h->s;STREC*p;{if(p->s>max)}return}#include<stdio.h>#include<string.h>#defineM5#defineNvoidfun(char{inti,j,n,len=0;for(i=0;i<M;i++){len=strlen(ss[i]);if(i==0)n=len;}for(i=0;i<M;i++){ for(j=0;j<len-n;j++)ss[i][ ]='*';ss[i][n+j+ }}{charss[M][N]={"shanghai","guangzhou","beijing","tianjing","cchongqing"};inti;printf("Theoriginalstringsare:\n");for(i=0;i<M;i++)printf("%s\n",ss[i]);printf("Theresultisfor(i=0;i<M;i++)}給定程序MODI1.C中fun函數(shù)的功能是:將p所指字符串中每個(gè)單詞的最后一個(gè)字母改成例如,若輸入"Iamastudenttotakethe則應(yīng)輸出"IaMAstudenTtOtakEthEexamination."。#include<ctype.h>voidfun(char*p){intk=for(;*p;p++)if(k){if(p==''{k=*(p-1)=toupper(*(p-1)}}k=}{charchrstr[64];intd;printf("\nPleaseenteranEnglishsentencewithin63letters:");d=strlen(chrstr);chrstr[d]='';chrstr[d+1]=0;printf("\n\nBeforechanging:\n%s",chrstr);printf("\nAfterchanging:\n%s",}請編寫函數(shù)fun,對長度為7個(gè)字符的字符串,除首、尾字符外,將其余5個(gè)字符按ASCII碼降例如,原來的字符串為CEAedca,排序后輸出為CedcEAa。#include<stdio.h>#include<ctype.h>#include<string.h>intfun(char*s,intnum){}{char}intfun(char*s,int{charch;inti,j;for(i=1;i<6;for(j=i+1;j<6;j++){if(*(s+i)<*(s+j)){ch=*(s+j)*(s+j)=*(s+i)*(s+i)=ch}}}#include<stdio.h>#include<string.h>structstudent{longsno;charname[10];floatscore[3];voidfun(structstudenta[],int{1t;inti,j;for(i=0;i<2;i++)for(j=i+1;j<n;j++)if(strcmp(3)>{t=a[i];a[i]=a[j];a[j]=t;}{structstudents[4]={{10001,"ZhangSan",95,80,88},{10002,"LiSi",85,70,{10003,"CaoKai",75,60,88},{10004,"FangFang",90,82,inti,printf("\n\nTheoriginaldata:\n\n");for(j=0;j<4;j++){printf("\nNo:%ldName:%-8sScores:",s[j].sno,s[for(i=0;i<3;i++)printf("%6.2f",s[j].score[i]);}fun(s,printf("\n\nThedataaftersorting:\n\n");for(j=0;j<4;j++){printf("\nNo:%ldName:%-8sScores:",s[j].sno,s[for(i=0;i<3;i++)printf("%6.2f",s[j].score[i]);}}fun(char*p){charmax,*q;inti=0;while(p[i]!=0{if(max<p[i]{/}}wihle(q>p}}{charprintf("Enterastring:");gets(str);printf("\nTheoriginalstring:");puts(str);printf("\nThestringaftermoving:");puts(str);}學(xué)生的記錄由學(xué)號和成績組成,N名學(xué)生的數(shù)據(jù)已在主函數(shù)中放入結(jié)構(gòu)體數(shù)組s中,請編寫例如,輸入的分?jǐn)?shù)是6069,則應(yīng)當(dāng)把分?jǐn)?shù)在60到69的學(xué)生數(shù)據(jù)進(jìn)行輸出,包含60分和69#defineN16typedefstruct{charnum[10];ints;}intfun(STREC*a,STREC*b,intl,inth{}{STRECSTRECh[N],tt;FILE*out;inti,j,n,low,heigh,t;printf("Enter2integernumberlow&heigh:");scanf("%d%d",&low,&heigh);if(heigh<low){t=heigh;heigh=low;low=t;}n=fun(s,h,low,heigh);printf("Thestudent'sdatabetween%d--%d:\n",low,heigh);for(i=0;i<n;i++)out=fopen("c:\\test\\out.dat","w");n=fun(s,h,80,98);for(j=i+1;j<n;j++)if(h[i].s>h[j].s){tt=h[i];h[i]=h[j];h[j]=tt;}for(i=0;i<n;i++)}intfun(STREC*a,STREC*b,intl,inth{inti,j=0for(i=0;i<N;if(a[i].s>=l&&a[i].s<=h)b[j++]=a[i];returnj;}#include<stdio.h>#include<stdlib.h>#include<string.h>char*fun(char*s){inti,j,k,n;char*p,*t;j=0;k=0;for(i=0;i<n;{if(((s[i]>='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))){t[j]=1;j++;}{p[k]=s[i];k++;}for(i=0;i<2;i++)t[j+i]=p[i];t[j+k]=3;return}{charprintf("Pleaseinput:");scanf("%s",s);printf("\nTheresultis:%s\n",fun(s));}給定程序MODI1.C中函數(shù)fun的功能是:將s例如,當(dāng)s所指字符串中的內(nèi)容為:"abcdabfabc",t1所指子串中的內(nèi)容為:"ab",t2所指子串中的內(nèi)容為:"99"時(shí),結(jié)果,在w所指的數(shù)組中的內(nèi)容應(yīng)為:#include<stdio.h>#includestring.h>intfun(char*s,char*t1,char*t2,char{inti;char*p,*r,*a;strcpy(w,s);while(w{p=w;r=t1;while(*r)IF(*r==*p{r++;p++;elseif(*r=='\0')a=w;}r=while(*r){*a=*r;a++;r++;}{chars[100],t1[100],t2[100],printf("\nPleaseenterstringS:");scanf("%s",s);printf("\nPleaseentersubstringt1:");scanf("%s",t1);printf("\nPleaseentersubstringt2:");scanf("%s",if(strlen(t1)==strlen(t2){fun(s,t1,t2,printf("\nTheresultis:%s\n",}elseprintf("\nError:strlen(t1)!=}#include<stdio.h>#include<string.h>voidfun(char*s,chart[]){}{chars[100],printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);}voidfun(char*s,char{inti,j=0for(i=0;i<strlen(s);i++)if(s[i]%2==0)t[j++]=s[i];t[j]=0;}ZhangSan95、80、88,修改后輸出t中的數(shù)據(jù)應(yīng)為:10002、"LiSi96、#include<stdio.h>#include<string.h>structstudent{longsno;charname[10];floatscore[3];1fun(structstudent{inta->sno=10002;strcpy(a->name,"LiSi");for(i=0;i<3;i++)2+=1;return3;}{structstudents={10001,"ZhangSan",95,80,88},*t;inti;printf("\n\nTheoriginaldataprintf("\nNo:%ldName:%s\nScores:",s.sno,);for(i=0;i<3;i++)printf("%6.2f",s.score[i]);t=printf("\nThedataaftermodifiedprintf("\nNo:%ldName:%s\nScores:",t->sno,t->name);for(i=0;i<3;i++)printf("%6.2f",t->score[i]);}第一處:必須定義結(jié)構(gòu)指針返回類型,所以應(yīng)填:structstudent*。#include<stdio.h>#include<string.h>#defineN5#defineM81fun(char(*sq)[M]){inti;char*sp;if(strlen(sp)<strlen(sq[i]))sp=sq[i];return}{charstr[N][M],*longest;inti;printf("Enter%dlines:\n",N);for(i=0;i<N;i++)gets(str[i]);printf("\nTheNstring:

溫馨提示

  • 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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論