二级C语言题库2_第1页
二级C语言题库2_第2页
二级C语言题库2_第3页
二级C语言题库2_第4页
已阅读5页,还剩64页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

二级C语言题库第21套题一、程序填空题#include<stdio.h>intfun(intx){intn,si,s2,s3,t;/**********lound**********/n=_1_;t=100;/**********found**********/whUe(t<=_2_){sl=t%10;s2=(t/10)%10;s3=t/100;if(sl+s2+s3==15){printf("%d",t);n++;/**********found**********/_3_;)returnn;)main(){intx=-l;while(x>999llx<0){printf("Pleaseinput(0<x<=999):");scanf("%d",&x);}printf("\nTheresultis:%d\n",fun(x));二、程序改错题#include<string.h>voidfun(char*s,char*t)/************found************/inti;si=strlen(s);for(i=0;i<sl;i++)/*********** nd************/t[i]=s[sl-i];for(i=0;i<sl;i++)t[sl+i]=s[i];t[2*sl]=4\0\main(){chars[100],t[100];printf("\nPleaseenterstrings:");scanf("%s",s);fun(s,t);printf("Theresultis:%s\n",t);三、程序编写题#include<stdio.h>voidfun(inta,intb,long*c)main()/*主函数*/{inta,b;longc;voidNONO();printf("Inputab:");scanf("%d%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);NONO();}voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen("K:\\k01\\24010001\\in.dat","r");wf=fopen("K:\\kO1W24010001\\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);}第22套题一、程序填空题#include<stdio.h>intfun(intx){intn,si,s2,s3,t;n=0;t=100;/**********found*********不/while(t<=—I—){/**********found**********/sl=t%l0;s2=(_2_)%10;s3=t/100;/**********found**********/if(sl+s2+s3==_3_){printf("%d",t);n++;t++;returnn;main(){intx=-l;while(x<0){printf("Pleaseinput(x>O):");scanf("%d",&x);}printf("\nTheresultis:%d\n",fun(x));二、程序改错题#include<stdio.h>/************found************/voidfun(longs,longt){longsl=10;s/=10;*t=s%10;/************]ound************/while(s<0){s=s/100;*t=s%10*sl+*t;si=si*10;main(){longs,t;printf("\nPleaseenters:");scanf("%ld",&s);fun(s,&t);printf("Theresultis:%ld\n",t);三、程序编写题#include<stdio.h>#defineN16typedefstruct{charnum[10];ints;}STREC;voidfun(STRECa[])main()STRECs[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},{"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87),{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91),{"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}};inti;FILE*out;fun(s);printf("Thedataaftersorted:\n");for(i=0;i<N;i++){if((i)%4==0)printf("\n");printf("%s%4d",s[i].num,s[i].s);}printf("\n");out=fopen("K:\\kO1W24010001\\out.dat","w");for(i=0;i<N;i++){if((i)%4==0&&i)fprintf(out,"\n");fprintf(out,"%4d",s[i].s);}fprintf(out,"\n");fclose(out);第23套题一、程序填空题#include<stdio.h>unsignedlongfun(unsignedlongn){unsignedlongx=0,s,i;intt;s=n;/**********found*********不/i=_l_;/**********found**********/while(_2_){t=s%10;if(t%2==0){/**********found**********/x=x+l*i;i=_3_;}s=s/10;}returnx;}main(){unsignedlongn=-l;while(n>99999999lln<0){ printf("Please input(O<n<l00000000): ");scanf("%ld",&n);}printf("\nTheresultis:%ld\n",fun(n));1二、程序改错题#include<stdio.h>#defineM5/************found************/intfun(intn,intxx[][]){inti,j,sum=0;printf("\nThe%dx%dmatrix:\n",M,M);for(i=0;i<M;i++){for(j=0;j<M;j++)/************fk'iund************/printf("%f",xx[i][j]);printf("\n");for(i=0;i<n;i++)sum+=xx[i][i]+xx[i][n-i-1];retum(sum);)main(){intaa[M][M]={{1,2,3,4,5),{4,3,2,1,0),{678,9,0},{9,8,7,6,5},{3,4,5,6,7}};printf("\nThesumofallelementson2diagnalsis%d.",fun(M,aa));}三、程序编写题#include<stdio.h>voidfun(inta,intb,long*c)main(){inta,b;longc;voidNONO();printf("Inputab:");scanf("%d%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);NONO();}voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen("K:\\k01\\24010001\\in.dat","r");wf=fopen("K:\\kO1W24010001\\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);第24套题一、程序填空题#include<stdio.h>unsignedlongfun(unsignedlongn){unsignedlongx=0;intt;while(n){t=n%10;/**********found**********/if(t%2==_l_)/**********found**********/x=—2—+t;/**********found*********不/n=_3_;Ireturnx;)main(){unsignedlongn=-l;while(n>99999999lln<0){ printf("Please input(O<n<l00000000): ");scanf("%ld",&n);}printf("\nTheresultis:%ld\n",fun(n));)二、程序改错题#include<stdio.h>voidfun(longs,long*t){intd;longsl=l;/************,0und************/t=0;while(s>0){d=s%10;/************tound************/if(d%2==0){*t=d*si+*t;si*=10;)s/=10;)}main(){longs,t;printf("\nPleaseenters:");scanf("%ld",&s);fun(s,&t);printf("Theresultis:%ld\n",t);}三、程序编写题#include<stdio.h>voidfun(charpl[],charp2[])main(){charsi[80],s2[40];voidNONO();printf("Entersiands2:\n");scanf("%s%s"»s1,s2);printf("s1=%s\n",si);printf("s2=%s\n",s2);printf("Invokefun(s1,s2):\n");fun(sl,s2);printf("Afterinvoking:\n");printf("%s\n",si);NONO();voidNONO(){/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/intFILE*rf,*wf;charsl[8O],s2[40];rf=fopen("K:\\kO1W24010001\\in.dat","r");wf=fopen("K:\\kO1W24010001\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%s"»si);fscanf(rf,"%s",s2);fun(sl,s2);fprintf(wf,"%s\n"»si);}fclose(rf);fclose(wf);}第25套题一、程序填空题#include<stdio.h>voidfun(unsignedlong*n){unsignedlongx=0,i;inti=l;while(*n)/********* nd**********/{t=*n%_1_;/**********found**********/if(t%2!=_2_){x=x+t*i;i=i*10;}*n=*n/10;/**********found*********不/*n=_3_;main(){unsignedlongn=-l;while(n>99999999lln<0){printf("Pleaseinput(O<n<100000000):");scanf("%ld",&n);}fun(&n);printf("\nTheresultis:%ld\n",n);二、程序改错题#include<stdio.h>doublefun(intn){doubleresult=1.0;/************found************/ jfn==0return1.0;while(n>l&&n<170)/***********************/resultreturnresult;main(){intn;printf("InputN:");scanf("%d",&n);printf("\n\n%d!=%lf\n\n",n,fun(n));}三、程序编写题#include<stdio.h>#include<string.h>longfun(char*p)/*以下代码仅供参考*/inti,len,t;/*len为串长,t为正负标识*/longx=0;len=strlen(p);if(p[O]=='-'){t=-l;len-;p++;}elset=1;/*以下完成数字字符串转换为一个数字*/returnx*t;}main()/*主函数*/{chars[6];voidNONO();longn;printf("Enterastring:\n");gets(s);n=fun(s);printf("%ld\n",n);NONO();)voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。FILE*fp,*wf;inti;chars[20];longn;fp=fopen("K:\\kO1W24010001\\in.dat","r");wf=fopen("K:\\kO1W24010001\\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);}第26套题一、程序填空题*/

#include<stdio.h>doublefun(intn){int{intdoubles,t;/**********found**********/s=_1—;/**********found**********/fbr(i=l;i<=_2_;i++){t=2.0*i;/**********tound**********/s=s+(2.0*i-l)*(2.0*i+1)/_3_;)returns;}main(){intn="l;while(n<O){printf("Pleaseinput(n>O):");scanf("%d",&n);printf("\nTheresultis:%f\n",fun(n));二、程序改错题#include<stdio.h>intfun(char*str,char*substr){inti,j,k,num=0;/************found************/for(i=0,str[ij,i++)for(j=i,k=0;substr[k]==str[j];k++,j++)/************found************/If(substr[k+l]==4\0,){num++;break;returnnum;main()charstr[80],substr[80];printf("Inputastring:");gets(str);printf("Inputasubstring:");gets(substr);printf("%d\n",fun(str,substr));三、程序编写题#include<stdio.h>#include<math.h>doublefun(doubleeps)main(){doublex;voidNONO();printf("Inputeps:");scanf("%lf",&x);printf("\neps=%lf,PI=%lf\n",x,fun(x));NONO();)voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*fp,*wf;inti;doublex;fp= fopen("K:\\kO1W24010001\\in.dat","r") ; wf=fopen("K:\\kO1\\24010001\\out.dat","w"); for(i=0;i<10;i++){fscanf(fp,"%lf",&x);fprintf(wf,"%lf\n",fun(x));fclose(fp);fclose(wf);第27套题一、程序填空题#include<stdio.h>doublefun(intn){inti,k;doubles,t;s=0;/**********found**********/k=_l_;fbr(i=l;i<=n;i++){/**********[ound**********/t=_2_;s=s+k*(2*i-1)*(2*i+l)/(t*t);/**********found**********/k=k*_3_;returnmain(){intn=-l;while(n<O){printf("Pleaseinput(n>O):");scanf("%d",&n);}printf("\nTheresultis:%f\n",fun(n));)二、程序改错题#include<stdio.h>intfun(intm){intk=2;while(k<=m&&(m%k))/************found************/k++/************tound************/if(m=k)return1;elsereturn0;main(){intn;printf("\nPleaseentern:");scanf("%d",&n);if(funn))printf("YES\n");elseprintf("NO!\n");}三、程序编写题#include<stdlib.h>#include<stdio.h>voidfun(inta[],intn,int*max,int*d)main(){inti,x[20],max,index,n=10;voidNONO();for(i=0;i<n;i++){x[ij=rand()%50;printf("%4d",x[ij);}printf("\n");fun(x,n,&max,&index);printf("Max=%5d,Index=%4d\n",max,index);NONO();voidNONO()FILE*fp,*wf;{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。inti,x[20],max,index,n=10,j;

FILE*fp,*wf;fp=fopen("K:\\k01\\2401(XM)l\\in.dat","r");wf=fopen("K:\\k01\\24010001\\out.dat","w");for(i=0;i<10;i++){for(j=0;j<n;j++)fscanf(fp,"%d,",&x[j]);fun(x,n,&max,&index);fprintf(wf,"Max=%d,Index=%d\n",max,index);)fclose(fp);fclose(wf);}第28套题一、程序填空题*/s=0;k=l;i=2;x=_1_/4;s=0;k=l;i=2;x=_1_/4;while(x—2_e)/**********found**********//*东东*******found**********/{s=s+k*x;k=k*(-1);t=2*i;/**********found**********/i++;)returns;)main(){doublee=le-3;printf("\nTheresultis:%fkn",fun(e));)二、程序改错题#include<stdio.h>/************found************/voidfun(intn){inta,b,c,k;doubles;s=0.0;a=2;b=1;for(k=l;k<=n;k++){/*********** nd************/s=s+(Double)a/b;c=a;a=a+b;b=c;returns;main(){intn=5;printf("\nThevalueoffunctionis:%lf\n",fun(n));程序编写题#include<stdio.h>#defineM4intfun(inta[][M])main(){intarr[2][M]={5,8,3,45,76,-4,12,82);voidNONO();printf("max=%d\n",fun(arr));NONO();voidNONO0{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*wf;intarr[][M]={5,8,3,90,76,412,82};wf=fopen("K:\\kO1W24010001\\out.dat","w");fprintf(wf,"max=%d\n",fun(arr));fclose(wf);)第29套题一、程序填空题#include<stdio.h>doublefun(doublee){inti;doubles,x;/**********[ound**********/s=0;i=_1x=1.0;while(x>e){/**********tound**********/_2_;/**********found**********/x=(2.0*i-1)/((_3_)*(2.0*i));s=s+x;}returns;}main(){doublee=le-3;printf("\nTheresultis:%f\n",fun(e));}二、程序改错题#include<stdio.h>#include<string.h>voidfun(chars,chart)(inti,d;d=strlen(s);for(i=0;i<d;i++)t[i]=s[i];for(i=0;i<d;i++)t[d+i]=s[d-l-i];/************found************/t[2*d-l]=4\0\}main()(chars[100],t[100];printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);}三、程序编写题#include<stdio.h>#include<string.h>voidfun(char*s,chart[J)main()(chars[100],t[100];voidNONO();printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);NONO();voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。chars[100],t[100];HLE*rf,*wf;inti;rf=fopen("K:\\kO1W24010001\\in.dat","r");wf=fopen("K:\\kO1W24010001\\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);}第30套题一、程序填空题*/#include<stdio.h>#include<stdlib.h>#include<string.h>char*fun(char*s){inti,j,k,n;char*p,*t;n=strlen(s)+1;t=(char*)malloc(n*sizeof(char));p=(char*)malloc(n*sizeof(char));j=0;k=0;for(i=0;i<n;i++){ if(((s[i]>=ta,)&&(s[i]<="z,))ll((s[i]>=4A,)&&(s[i]<=*Z,))){/**********f^^und**********/t[j]=_l_;j++;}else{p[k]=s[i];k++;}/**********found**********/for(i=0;i<_2_;i++)t[j+i]=p[i];/**********found*********不/t[j+k]=_3_;returnt;main(){chars[80];printf("Pleaseinput:");scanf("%s",s);printf("\nTheresultis:%s\n",fun(s));)二、程序改错题#include<stdio.h>#include<string.h>voidfun(char*s,char*tl,char*t2,char*w){char*p,*r,*a=s;strcpy(w,s);/************found************/while(w){p=w;r=tl;while(*r)/************found************/IF(*r==*p){r++;p++;}elsebreak;if(*r=='\0')a=w;w++;)r=t2;while(*r){*a=*r;a++;r++;}}main()(chars[100],tl[100],t2[100],w[100];printf("\nPleaseenterstringS:");scanf("%s"»s);printf("\nPleaseentersubstringtl:");scanf("%s",tl);printf("\nPleaseentersubstringt2:");scanf("%s",t2);if(strlen(t1)==strlen(t2)){fun(s,tl,t2,w);printf("\nTheresultis:%s\n",w);)elseprintf("\nError:strlen(tl)!=strlen(t2)\n");}三、程序编写题#include<stdio.h>#include<string.h>voidfun(char*s,chart[])main()(chars[100],t[100];voidNONO();printf("\nPleaseenterstringS:");scanf("%s",s);fun(s,t);printf("\nTheresultis:%s\n",t);NONO();}voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。chars[100],t[100];FILE*rf,*wf;inti;rf=fopen("K:\\kO1W24010001\\in.dat","r");wf=fopen("K:\\kO1\\24010001\\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);

*/第31套题一、程序填空题#include<stdio.h>#define N 3#define M 4/**********found**********/voidfun(int(*a)[N],int_1_){inti,temp;/**********[ound**********/for(i=0;i<_2_;i++){temp=a[0][i];/**********found**********/a[0][i]=_3_;a[k][i]=temp;main()printf("Thearraybeforeprintf("\n\n");{intx[M][N]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}},i,j;printf("Thearraybeforeprintf("\n\n");moving:\n\n");for(i=0;i++){for(j=0;j&It;N;j++)printf("%3d",x[i][j])»fun(x,2);printf("Thearrayaftermoving:\n\n");for(i=0;i++){for(j=0;j<N;j++)printf("%3d",x[i][j]);printf("\n\n");二、程序改错题#include<stdio.h>#include<string.h>voidfun(chart[])charc;inti,j;/**********found***********/for(i=strlen(t);i;i—)for(j=0;j<i;j++)/**********found***********/if(t[j]<t[j+l])c=t[j];t[j]=t[j+l];tu+1]=C;}main()(chars[81];printf("\nPleaseenteracharacterstring:");gets(s);printf("\n\nBeforesorting:\n\"%s\"",s);fun(s);printf("\nAftersortingdecendingly:\n\"%s\"\n",s);}三、程序编写题#include<stdio.h>#include<string.h>voidfun(char*ss)voidmain(void)(chartt[51];voidNONO();printf("\nPleaseenterancharacterstringwithin50characters:\n");gets(tt);printf("\n\nAfterchanging,thestring\n\"%s\"",tt);fun(tt);printf("\nbecomes\n\"%s\"",tt);NONO。;)voidNONO()(/*请在此函数输出数据,关闭文件。*/chartt[51],ch;FILE*rf,*wf;intlen,i=0;rf=fopen("K:\\k01\\24010001\\in.dat","r");wf=fopen("K:\\kO1W24010001\\out.dat","w");while(i<10){fgets(tt,50,rf);len=strlen(tt)-1;ch=ttflen];if(ch==An'IIch==Oxla)tt[len]=0;fun(tt);fprintf(wf,"%s\n",tt);i++;}fclose(rf);fclose(wf);}第32套题一、程序填空题#include#define#define<stdio.h>M3N5voidfun(int(*a)[N],intk){inti,j,p,temp;/**********found*********不/for(p=l;p<=_1_;p++)

for(i=0;i++){temp=a[i][O];/**********found*********不/for(j=0;j<_2_;j++)a[i][j]=a[i][j+l];/**********found**********/a[i][N-l]=_3_;main(){intx[M][N]={{1,2,3,4,5},{1,2,3,4,5},{1,2,345}},i,j;printf("Thearraybeforemoving:\n\n");for(i=0;i++){for(j=0;j≪N;j++)printf("%3d",x[i][j]);printf("\n");}fun(x,2);printf("Thearrayaftermoving:\n\n");for(i=0;i++){for(j=0;j<N;j++)printf("%3d",x[i][j]);printf("\n");}I二、程序改错题#include<conio.h>#include<stdio.h>#defineM10inta[M][M]={0};{intj,k;for(j=0;j<m;j++)for(k=0;k<m;k++)a[j][k]=k*j;/**************a[j][k]=k*j;main(){inti,j,n;printf("Entern:");scanf("%d",&n);fun(a,n);for(i=0;i<n;i++){for(j=0;j<n;j++)printf("%4d",a[i][j]);printf("\n");})三、程序编写题#include≪sldio.h>voidfun(inta,intb,long*c)()main(){inta,b;longc;voidNONO();printf("Inputab:");scanf("%d%d".&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);NONO();)voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen("K:\\k01\\24010001\\in.dat"T"r");wf=fopen("K:\\kOIW240100()1\\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);第33套题一、程序填空题#include&)t;stdio.h>#define M 3#define N 4voidfun(int(*a)[N]){inti=O,j,find=O,rmax,c,k;while((i<M)&&(!find)){rmax=a[i][0];c=0;for(j=1;j<N;j++)if(rmax<a[i][j]){/**********found**********/rmax=a[i][j];c=_1_;}find=l;k=0;while(k<M&&find){/**********found**********/if(k!=i&&a[k][c]<=rmax)find=—2—; k++;)if(find)printf("find:a[%d]l%dj=%d\n",i,c,ali][c]);/**********fOund**********/_3_;}if(!find)printf("notfound!\n");)main(){intx[M][N],ij;printf("Enternumberforarray:\n");for(i=0;i++)for(j=0;j<N;j++)scanf("%d",&x[i][j]); printf("Thearray:\n");for(i=0;i<M;i++){for(j=0;j<N;j++)printf("%3d",x[i][j]);printf("\n\n");)fun(x);二、程序改错题

#include<stdio.h>doublefun(intm){doubley=1.0;inti;for(i=2;i<m;i++)

y-=1/(i*i);/**************foundfor(i=2;i<m;i++)

y-=1/(i*i);}main(){intn=5;printf("\nTheresultis%lf\n",fun(n));)三、程序编写题#include<stdio.h>#include<string.h>intfun(intscore[J,intm,intbelow[J)main(){inti,n,below[9];voidNONO();intscore[9]={10,20,30,40,50,60,70,80,90);n=fun(score,9,below);printf("\nBelowtheaveragescoreare:");for(i=0;i<n;i++)printf("%d",belowfi]);NONO();voidNONO(){/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/ inti,j,n,below[10],scoreflO];HLE*rf,*wf;rf=fopen("K:\\k01\\24010001\\in.dat","r");wf=fopen("K:\\kO1W2401OCX)1\\out.dat","w");for(i=0;i<10;i++){for(j=0;j<10;j++)fscanf(rf,"%d",&score(j]);n=fun(score,10,below);for(j=0;j<n;j++)fprintf(wf,"%d",below[j]);fprintf(wf,"\n");}fclose(rf);fclose(wf);}第34套题一、程序填空题#include<stdio.h>#include<string.h>#defineN80voidfun(char*s,intn,char*t){intlen,i,j=0;len=strlen(s);/**********found**********/if(n>=len)strcpy(_1_);else{/**********found**********/for(i=len-n;i<=len-l;i++)t|j4-+J=_2_;/**********found**********/t[j]=_3—;main(){chars[N],t[N];intn;printf("Entern:");printf("Enterastring: ");gets(s);printf("Entern:");scanf("%d",&n);fun(s,n,t);printf("Thestringt:");puts(t);}二、程序改错题#include<stdio.h>intfun(intm){inti,k;for(i=m+1;;i++){for(k=2;k<i;k++)/**************tound**************/if(i%k!=0)break;/**************found**************/if(k<i)return(i);voidmain()intn;n=fun(20);printf("n=%d\n",n);三、程序编写题#include<stdio.h>voidfun(intx,intpp[J,int*n)

main(){intx,aa[1000],n,i;voidNONO();printf("\nPleaseenteranintegernumber:\n");scanf("%d",&x);fun(x,aa,&n);for(i=0;i<n;i++)printf("%d",aa[i]);printf("\n");NONO();voidNONO(){/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/ intx,aa[1000],n,i,j;FILE*fp;fp=fopen("K:\\kO1W24010001\\out.dat","w");for(j=0;j<10;j++){x=30+j;fun(x,aa,&n);for(i=0;i<n;i++)fprintf(fp,"%d",aa[i]);fprintf(fp,"\n");}fclose(fp);}第35套题一、程序填空题#include#include#include#include#include<string.h><ctype.h>intfun(char*s){char*lp,*rp;/**********found**********/lp=_1—;rp=s+strlen(s)-1;while((toupper(*lp)==toupper(*rp))&&(lp<rp)){/**********found*********不/lp++;rp_2_;}/**********found**********/if(lp<rp)_3_;elsereturn1;)main(){chars[81];printf("Enterastring:");scanf("%s",s);if(fun(s))printf("\n\"%s\"isaPalindrome.\n\n",s);elseprintf("\n\"%s\"isn'taPalindrome.\n\n",s);}二、程序改错题#include<stdio.h>/**************found**************/fun(intn){inta=2,b=1,c,k;doubles=0.0;for(k=1;k<=n;k++){s=s+1.0*a/b;/**************found**************/c=a;a+=b;b+=c;retum(s);main(){intn=5;printf("\nThevalueoffunctionis:%lf\n",fun(n));}三、程序编写题voidfun(intm,intk,intxx[])/*以下代码仅供参考*/inti,j=l,t=m+1;while(j<;=k)(/*以下完成判断素数,并存放到数组XX中*/main()(intm,n,zz[1000];voidNONO();printf("\nPleaseentertwointegers:");scanf("%d%d",&m,&n);fun(m,n,zz);for(m=0;m<n;m++)printf("%d",zz[m]);printf("\n");NONO();}voidNONO(){/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/intm,n,zz[lOOOJ,i;FILE*rf,*wf;rf=fopen("K:\\kO1\\24010001\\in.dat","r");wf=fopen("K:\\kO1W24010001\\out.dat","w");for(i=0;i<10;i++){fscanf(rf,"%d%d",&m,&n);fun(m,n,zz);for(m=0;m<n;m++)fprintf(wf,"%d",zz[mj);fprintf(wf,"\n");}fclose(rf);fclose(wf);第36套题一、程序填空题#include<stdio.h>intfun(char*s){intn=0,flag=0;while(*s!=t\0,){if(*s!=4'&&flag==0){/**********lound**********/_1_;flag=l;}/**********found**********/if(*s=44)flag=_2_;/**********[ound**********/3;returnn;main(){charstr[81];intn;printf("\nEnteralinetext:\n");gets(str);n=fun(str);printf("\nThereare%dwordsinthistext.\n\n",n);}二、程序改错题#include<stdio.h>#defineN20intfun(float*s,intn,float*aver){floatave,t=0.0;intcount=0,k,i;for(k=0;k<n;k++)/**************found**************/t=s[k];for(i=0;i<n;i++)if(s[i]<ave)count++;/**************{ound**************/*aver=Ave;returncount;)main(){floats[30],aver;intm,i;printf("\nPleaseenterm:");scanf("%d",&m);printf("\nPleaseenter%dmark:\n",m);for(i=0;i<m;i++)scanf("%f",s+i);printf("\nThenumberofstudents:%d\n",fun(s,m,&aver));printf("Ave=%f\n",aver);三、程序编写题#include<stdio.h>voidfun(int*s,intt,int*k)main()inta(10]={876,675,896,101,301,401,980,431,451,777},k;voidNONO();fun(a,10,&k);printf("%d,%d\n",k,a[k]);NONO();voidNONO(){/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/inta[10],i,kJ;FILE*rf,*wf;rf=fopen("K:\\kO1W24010001\\in.dat","r");wf=fopen("K:\\kO1W24010001\\out.dat","w");for(i=0;i<10;i++){for(j=0;j<10;j++)fscanf(rf,"%d",&a[j]);fun(a,10,&k);fprintf(wf,"%d,%d\n",k,a[k]);)fclose(rf);fclose(wf);}第37套题一、程序填空题#include<stdio.h>intfun(char*s,char*t){intn=0;while(*s){if(*s<97){/**********found**********/*(t+n)=_l_;n++;}/**********found**********/2;♦(t+n)=0;/**********found**********/return_3_;main(){chars[81],t[81];intn;printf("\nEnterastring:\n");gets(s);n=fun(s,t);printf("\nThereare%dletterwhichASCIIcodeislessthan97:%s\n",n,t);}二、程序改错题#include<stdio.h>intfun(doublex[],intn)/*********** nd************/intj,c=0,doublexa=0.0;for(j=0;j<n;j++)xa+=x[j]/n;printf("ave=%f\n",xa);for(j=O;j<n;j++)/************found************/if(x[j]=>xa)C++;returnc;)main(){doublex[100]={193.199,195,673,195.757,196.051,196.092,196.596,196.579,196.763);printf("%d\n",fun(x,8));}三、程序编写题#include<stdio.h>floatfun(intm,intn)main()/*主函数*/{voidNONO();printf("P=%f\n",fun(12,8));NONO();voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*fp,*wf;inti,m,n;floats;fp=fopen("K:\\k01\\2401(XX)l\\in.dat","r");wf=fopen("K:\\kO1W24010001\\out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%d,%d",&m,&n);s=fun(m,n);fprintf(wf,"%f\n",s);}fclose(fp);fclose(wf);第38套题一、程序填空题#include<stdio.h>#include<string.h>#include<ctype.h>intfun(char*s){intsum=0;while(*s){isdigjt(*s))sum+=*s- | */**********found**********//**********found**********/return3

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论