您好,欢迎访问三七文档
1第1套题一、程序填空题#includestdio.h#includestdlib.h#defineN5typedefstruct{intnum;charname[10];chartel[10];}STYPE;voidcheck();/**********found**********/intfun(___1___*std){/**********found**********/___2___*fp;inti;if((fp=fopen(myfile5.dat,wb))==NULL)return(0);printf(\nOutputdatatofile!\n);for(i=0;iN;i++)/**********found**********/fwrite(&std[i],sizeof(STYPE),1,___3___);fclose(fp);return(1);}main(){STYPEs[10]={{1,aaaaa,111111},{1,bbbbb,222222},{1,ccccc,333333},{1,ddddd,444444},{1,eeeee,555555}};intk;2k=fun(s);if(k==1){printf(Succeed!);check();}elseprintf(Fail!);}voidcheck(){FILE*fp;inti;STYPEs[10];if((fp=fopen(myfile5.dat,rb))==NULL){printf(Fail!!\n);exit(0);}printf(\nReadfileandoutputtoscreen:\n);printf(\nnumnametel\n);for(i=0;iN;i++){fread(&s[i],sizeof(STYPE),1,fp);printf(%6d%s%s\n,s[i].num,s[i].name,s[i].tel);}fclose(fp);}二、程序改错题#includestdio.h#includestring.hvoidfun(char*s,char*t){inti,sl;sl=strlen(s);/************found************/for(i=0;i=s1;i++)t[i]=s[i];for(i=0;i=sl;i++)3t[sl+i]=s[sl-i-1];/************found************/t[sl+s1]='\0';}main(){chars[100],t[100];printf(\nPleaseenterstrings:);scanf(%s,s);fun(s,t);printf(Theresultis:%s\n,t);}三、程序编写题#includestdio.hvoidfun(inta,intb,long*c){*c=(a/10)*1000+(b/10)*100+(a%10)*10+(b%10);}main(){inta,b;longc;voidNONO();printf(Inputab:);scanf(%d%d,&a,&b);fun(a,b,&c);printf(Theresultis:%d\n,c);NONO();}voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*rf,*wf;4inti,a,b;longc;rf=fopen(K:\\k01\\24010001\\in.dat,r);wf=fopen(K:\\k01\\24010001\\out.dat,w);for(i=0;i10;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套题一、程序填空题#includestdio.h#includestring.h#includestdlib.hvoidWriteText(FILE*);voidReadText(FILE*);main(){FILE*fp;if((fp=fopen(myfile4.txt,w))==NULL){printf(openfail!!\n);exit(0);}WriteText(fp);fclose(fp);if((fp=fopen(myfile4.txt,r))==NULL){printf(openfail!!\n);exit(0);}5ReadText(fp);fclose(fp);}/**********found**********/voidWriteText(FILE___*fw___){charstr[81];printf(\nEnterstringwith-1toend:\n);gets(str);while(strcmp(str,-1)!=0){/**********found**********/fputs(___str___,fw);fputs(\n,fw);gets(str);}}voidReadText(FILE*fr){charstr[81];printf(\nReadfileandoutputtoscreen:\n);fgets(str,81,fr);while(!feof(fr)){/**********found**********/printf(%s,___str__);fgets(str,81,fr);}}二、程序改错题#includestdio.h/************found************/voidfun(longs,long*t){longsl=10;*t=s%10;while(s0)6{s=s/100;*t=s%10*sl+*t;/************found************/sl=sl*10}}main(){longs,t;printf(\nPleaseenters:);scanf(%ld,&s);fun(s,&t);printf(Theresultis:%ld\n,t);}三、程序编写题#includestdio.h#defineN16typedefstruct{charnum[10];ints;}STREC;intfun(STREC*a,STREC*b){inti,j=0,min=a[0].s;for(i=0;iN;i++){if(a[i].smin){j=0;b[j++]=a[i];min=a[i].s;7}elseif(min==a[i].s)b[j++]=a[i];}returnj;}main(){STRECs[N]={{GA05,85},{GA03,76},{GA02,69},{GA04,85},{GA01,91},{GA07,72},{GA08,64},{GA06,87},{GA015,85},{GA013,91},{GA012,64},{GA014,91},{GA011,91},{GA017,64},{GA018,64},{GA016,72}};STRECh[N];inti,n;FILE*out;n=fun(s,h);printf(The%dlowestscore:\n,n);for(i=0;in;i++)printf(%s%4d\n,h[i].num,h[i].s);printf(\n);out=fopen(K:\\k01\\24010001\\out.dat,w);fprintf(out,%d\n,n);for(i=0;in;i++)fprintf(out,%4d\n,h[i].s);fclose(out);}第3套题一、程序填空题8#includemath.h#includestdio.hintfun(char*fname){FILE*fp;inti,n;floatx;if((fp=fopen(fname,w))==NULL)return0;for(i=1;i=10;i++)/**********found**********/fprintf(___fp__,%d%f\n,i,sqrt((double)i));printf(\nSucceed!!\n);/**********found**********/__fclose(fp)__;printf(\nThedatainfile:\n);/**********found**********/if((fp=fopen(___myfile3.txt__,r))==NULL)return0;fscanf(fp,%d%f,&n,&x);while(!feof(fp)){printf(%d%f\n,n,x);fscanf(fp,%d%f,&n,&x);}fclose(fp);return1;}main(){charfname[]=myfile3.txt;fun(fname);}二、程序改错题#includestdio.h#includestdlib.h9voidfun(intn,int*a){inti,j,p,t;for(j=0;jn-1;j++){p=j;/************found************/for(i=j+1;in;i++)if(a[p]a[i])/************found************/p=i;if(p!=j){t=a[j];a[j]=a[p];a[p]=t;}}}voidputarr(intn,int*z){inti;for(i=1;i=n;i++,z++){printf(%4d,*z);if(!(i%10))printf(\n);}printf(\n);}main(){intaa[20]={9,3,0,4,1,2,5,6,8,10,7},n=11;printf(\n\nBeforesorting%dnumbers:\n,n);putarr(n,aa);fun(n,aa);printf(\nAftersorting%dnumbers:\n,n);putarr(n,aa);}三、程序编写题#includestdio.hvoidfun(inta,intb,long*c)10{*c=(b%10)*1000+(a%10)*100+(b/10)*10+a/10;}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:\\k01\\24010001\\out.dat,w);for(i=0;i10;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套题一、程序填空题11#includestdio.h#includestdlib.hintfun(char*source,char*target){FILE*fs,*ft;charch;/**********found**********/if((fs=fopen(source,__r___))==NULL)return0;if((ft=fopen(target,w))==NULL)return0;printf(\nThedatainfile:\n);ch=fgetc(fs);/**********found**********/while(!feof(_
本文标题:二级C语言上机题库
链接地址:https://www.777doc.com/doc-5239018 .html