版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
全國計算機等級教育二級c語言考試原題及答案綠色部分為題目的問題位置,紅色部分為答案本題庫為全國計算機二級C語言上機考試原題,全部上機題庫均出自此100套題,每次考試從中選50套。第01套:是給定程序的功能是調(diào)用fun函數(shù)建立班級通訊錄.通訊錄中記錄每位學(xué)生的編號、姓名和電話號碼。班級的人數(shù)和學(xué)生的信息從鍵盤讀入,每個人的信息作為ー個數(shù)據(jù)塊寫到名為myfile5.dat的二進制文件中。請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。注意:源程序存放在考生文件夾下的BLANK1.C中。不得增行或刪行,也不得更改程序的結(jié)構(gòu)!給定源程序:^include<stdio.h>ftinclude<stdlib.h>8defineN5typedefstruct{intnum;charname[10];chartel[10];}STYPE;voidcheck();/**********found**********/intfun( 1*std)(/**********found**********/*fp;inti;if((fp=fopenC/myfile5.dat","wb"))==NULL)return(0);printf(*\n0utputdatatofile!\n");for(i=0;i<N;i++)/**********found**********/fwrite(&std[i],sizeof(STYPE),1? 」 );fclose(fp);return(1);}main(){STYPEs[10]={ {1,"aaaaa","111111”},{1,"bbbbb",“222222”},{Ijccccc”,"333333”},{Ijddddd,*444444"},{1Jeeeee*,*555555"});intk;k=fun(s);if(k==l){printf("Succeed!");check();}elseprintf("Fai1!");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;i<N;i++){fread(&s[i],sizeof(STYPE),1,fp);printf("%6d%s%s\n”,s[i]?num,s[i].name,s[i].tel);}fclose(fp);}解題答案:^include<stdio.h>#include<stdlib.h>^defineN5typedefstruct{intnum;charname[10];chartel[10];}STYPE;voidcheck();/**********found**********/intfun(STYPE*std)(/**********found**********/FILE*fp;inti;if((fp二fopen("myfile5.dat","wb"))==NULL)return(0);printf(*\n0utputdatatofile!\n");for(i=0;i<N;i++)/**********found**********/fwrite(&std[i],sizeof(STYPE),1,fp);fclose(fp);return(1);}main(){STYPEs[10]={{l,"aaaaa","111111"},{1,"bbbbb“222222”},{1,"ccccc","333333”},{1,"ddddd","444444”},{1,eeeee","555555”}};intk;k=fun(s);if(k=l){printf("Succeed!");check();}elseprintf("Fail!");voidcheck(){FILE*fp;inti;STYPEs[10];if((fp=fopen("myfile5.dat","rb"))==NULL){printf(*Fail!!\n*):exit(O);)printf("\nReadfileandoutputtoscreen:\n");printf("\nnumnametel\n");for(i=0:i<N;i++){fread(&s[i],sizeof(STYPE),1,fp);printf("%6d%s%s\n”,s[i].num,s[i].name,s[i],tel);}fclose(fp);}給定程序MOD"C中函數(shù)fun的功能是:先將在字符串s中的字符按正序存放到t串中,然后把s中的字符按逆序連接到t串的后面。例如:當(dāng)s中的字符串為:"ABCDE"時,則t中的字符串應(yīng)為:"ABCDEEDCBA”。請改正程序中的錯誤,使它能得出正確的結(jié)果。注意:不要改動main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!給定源程序:^include<stdio.h>#include<string.h>voidfun(char*s,char*t){inti,si;si=strlen(s);/************found************/for(i=0;i<=sl;i++)t[i]=s[i];for(i=0;i<sl;i++)t[sl+i]=s[sl-i-l];/************found************/t[sl]='、0';}main(){chars[100],t[100];printf(*\nPleaseenterstrings:");scanf(*%s*,s);fun(s,t);printf(*Theresultis:%s\n*,t);)解題答案:#include<stdio.h>0include<string.h>voidfun(char*s,char*t){inti,si;si=strlen(s);/************found************/for(i=0;i<=si;i++)t[i]=s[i];for(i=0;i<sl;i++)t[sl+i]=s[sl-i-l];/************found************/t[2*sl]=‘、〇';}main(){chars[100],t[100];printf〈’\nPleaseenterstrings:*);scanf('%s”,s);fun(s,t);printf(*Theresultis:%s\n”,t);}函數(shù)fun的功能是:將兩個兩位數(shù)的正整數(shù)a、b合并形成一個整數(shù)放在c中。合并的方式是:將a數(shù)的十位和個位數(shù)依次放在c數(shù)的千位和十位上,b數(shù)的十位和個位數(shù)依次放在c數(shù)的百位和個位上。例如,當(dāng)a=45,b=l2時,調(diào)用該函數(shù)后,c=4152?注意:部分源程序存在文件PROG1.C中。數(shù)據(jù)文件IN.DAT中的數(shù)據(jù)不得修改。請勿改動主函數(shù)main和其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入你編寫的若干語句。給定源程序:#include<stdio.h>voidfun(inta,intb,long*c)main(){inta,b;longc;voidNONO();printf(*Inputa,b:");scanf("%d,%d”,&a,&b);fun(a,b,&c);printf(*Theresultis:%d\n,c);NONO();}voidNONO(){/?本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen("in.dat","r");wf=fopen("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);}解題答案:#include<stdio.h>voidfun(inta,intb,long*c){*c=(a/10)*1000+(b/10)*100+(a%10)*10+(b%10);}main(){inta,b:longc;voidNONO();printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%d\n",c);N0N0():}voidNONO(){/?本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen(*in.dat",'r");wf=fopen(*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);)※※※※※※※※※※※※※※※※※※※※※※派※※第02套:是給定程序的功能是:從鍵盤輸入若干行文本(每行不超過80個字符),寫到文件myfile4.txt中,用ー1作為字符串輸入結(jié)束的標(biāo)志。然后將文件的內(nèi)容讀出顯示在屏幕上。文件的讀寫分別由自定義函數(shù)ReadText和WriteText實現(xiàn)。請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。注意:源程序存放在考生文件夾下的BLANK1.C中。不得增行或刪行,也不得更改程序的結(jié)構(gòu)!給定源程序:0include<stdio.h>^include<string.h>#include<stdlib.h>voidWriteText(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"))==NULD{printf("openfail!!\n");exit(0);}ReadText(fp);fclose(fp);}/**********found**********/voidWriteText(FILE 1 ){charstr[81];printf("\nEnterstringwith-1toend:\n");gets(str);while(strcmp(str,"-1")!=0){/**********found**********/fputs( 2 ,fw);fputs("\n",fw);gets(str);}}voidReadText(FILE*fr){charstr[81];printf("\nReadfileandoutputtoscreen:\n");fgets(str,81,fr);while(!feof(fr)){/**********found**********/printf("%s", 3 );fgets(str,81,fr);)}解題答案:#include<stdio.h>#include<string.h>^include<stdlib.h>voidWriteText(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);)ReadText(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);})給定程序MODILC中函數(shù)fun的功能是:從低位開始取出長整型變量s中奇數(shù)位上的數(shù),依次構(gòu)成一個新數(shù)放在t中。高位仍在高位,低位仍在低位。例如,當(dāng)s中的數(shù)為:7654321時,I中的數(shù)為:7531c請改正程序中的錯誤,使它能得出正確的結(jié)果。注意:不要改動main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!給定源程序:#include<stdio.h>/************found************/voidfun(longs,longt){longsl=10;*t=s%10;while(s>0){s=s/100;*t=s%10*si+*t;/林**********found************/si=s1*100;))main(){longs,t;printf("\nPleaseenters:");scanf("%ld",&s);fun(s,&t);printf(*Theresultis:%ld\n*,t);}解題答窠:#include<stdio.h>/************found************/voidfun(longs,long*t){longsl=10;*t=s%10;while(s>0){s=s/100;*t=s%10*si+*t;/************found************/sl=sl*10;))main(){longs,t;printf("\nPleaseenters:");scanf("%ld',&s);fun(s,&t);printf(*Theresultis:%ld\n”,t);)函數(shù)fun的功能是:將兩個兩位數(shù)的正整數(shù)a、b合并形成一個整數(shù)放在c中。合并的方式是:將a數(shù)的十位和個位數(shù)依次放在c數(shù)的個位和百位上,b數(shù)的十位和個位數(shù)依次放在c數(shù)的千位和十位上。例如,當(dāng)a=45,b=12時,調(diào)用該函數(shù)后,c=1524<,注意:部分源程序存在文件PROG1.C中。數(shù)據(jù)文件IN.DAT中的數(shù)據(jù)不得修改。請勿改動主函數(shù)main和其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入你編寫的若干語句。給定源程序:#include<stdio.h>voidfun(inta,intb,long*c)main(){inta,b;longc;voidNONO();printf(*Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf(*Theresultis:%ld\n”,c);N0N0();}voidNONO(){/?本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen("in.dat",r);wf=fopen(*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);}解題答案:#include<stdio.h>voidfun(inta,intb,long*c){*c=(b/10)*1000+(a%10)*100+(b%10)*10+(a/10);}main(){inta,b;longc;voidNONO();printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);N0N0();}voidNONO(){/?本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen("in.dat","r");wf=fopen("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);}※※※※※※※※※※※※※※※※※派※※※※※※※笫03套:是給定程序中,函數(shù)fun的功能是:將自然數(shù)1-10以及它們的平方根寫到名為myfile3.txt的文本文件中,然后再順序讀出顯示在屏幕上。請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。注意:源程序存放在考生文件夾下的BLANK1.C中。不得增行或刪行,也不得更改程序的結(jié)構(gòu)!給定源程序:#include<math.h>^include<stdio.h>intfun(char*fname){FILE*fp;inti,n;floatx;if((fp=fopen(fname,"w"))ニニNULL)return0;forgK10;i++)/**********found**********/fprintf( 1 ,"%d%f\n",i,sqrt((double)i));printf("\nSucceed!!\n");/**********found**********/—2—;printf("\nThedatainfile:\n");/**********found**********/if((fp=fopen(工,"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);)解題答案:^include<math.h>#include<stdio.h>intfun(char*fname){FILE*fp;inti,n;floatx;if((fp=fopen(fname,"w"))ニニNULL)return0;for(i=l;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(fname,"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;/************found************/)for(i=j+l;i<n;i++)main()if(a[p]>a[i]){charfname[]=*myfile3.txt*;/************found************/fun(fname);P=i;)if(p!=j)***************************************************{t=a[j];a[j]=a[p];a[p]=t;}給定程序MODH.C中fun函數(shù)的功能是:將n個無序整數(shù)從小到)大排序。請改正程序中的錯誤,使它能得出正確的結(jié)果。)注意:不要改動main函數(shù),不得增行或刪行,也不得更改程序的putarr(intn,int*z)結(jié)構(gòu)!給定源程序:{inti;#include<stdio.h>for(i=1;i<=n;i++,z++)^include<stdlib.h>{printf("%4d",*z);fun(intn,int*a)if(!(i%10))printf("\n");{inti,j,p,t;}printf("\n");for(j=0;j<n-l;j++)}{p=j;main()/************found************/{intaa[20]={9,3,0,4,1,2,5,6,8,10,7},n=l1;for(i=j+l;i<n-l;i++)printf("\n\nBeforesorting/dnumbers:\n",n);putarr(n,if(a[p]>a[i])aa):/************found************/fun(n,aa);t=i;printf("\nAftersorting%dnumbers:"",n);putarr(n,if(p!=j)aa):{t=a[j];a[j]=a[p];a[p]=t;}))***************************************************)函數(shù)fun的功能是:將兩個兩位數(shù)的正整數(shù)a、b合并形成一個整putarr(intn,int*z)數(shù)放在c中。合并的方式是:將a數(shù)的十位和個位數(shù)依次放在c{inti;數(shù)的個位和百位上,b數(shù)的十位和個位數(shù)依次放在c數(shù)的十位和千for(i=1;i<=n;i++,z++)位上。{printf(*%4d*,*z);例如,當(dāng)a=45,b=12時,調(diào)用該函數(shù)后,c=2514。if(!(i%10))printf('\n");注意:部分源程序存在文件PROG1.C中。數(shù)據(jù)文件IN.DAT中的}printf("\n");數(shù)據(jù)不得修改。}請勿改動主函數(shù)main和其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的main()花括號中填入{intaa[20]={9,3,0,4,1,2,5,6,8,10,7},n=ll;你編寫的若干語句。printf(*\n\nBeforesorting%dnumbers:\n*,n);putarr(n,給定源程序:aa);^include<stdio.h>fun(n,aa);voidfun(inta,intb,long*c)printf("\nAftersorting%dnumbers:\nz/,n);putarr(n,aa);}(解題答案:main()#include<stdio.h>{inta,b;longc;0include<stdlib.h>voidNONO();fun(intn,int*a)printf("Inputa,b:");{inti,j,p,t;scanf("%d,%d",&a,&b);for(j=0;j<n-l;j++)fun(a,b,&c);{p=j;printf("Theresultis:%ld\n",c);NONOO:NONOO:voidfiin(inta,intb,long*c)voidNONO(){/?本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen(*in.dat*,"r");wf=fopen("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);}解題答案:^include<stdio.h>voidfun(inta,intb,long*c){*c=(b%10)*1000+(a%10)*100+(b/10)*10+a/10;}main(){inta,b;longc;voidNONO();printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);N0N0();}voidNONO(){/?本函數(shù)用于打開文件,輸入數(shù)據(jù)「調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen("in.dat","r");wf=fopen("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);}參考答窠:*c=(b%10)*1000+(a%10)*100+(b/l0)*10+(a/10);)※※※※※※※※※※※※※※※※※※※※※※※派※第04套:是給定程序的功能是:調(diào)用函數(shù)fun將指定源文件中的內(nèi)容復(fù)制到指定的目標(biāo)文件中,復(fù)制成功時函數(shù)返回值為!,失敗時返回值為〇〇在復(fù)制的過程中,把復(fù)制的內(nèi)容輸出到終端屏幕。主函數(shù)中源文件名放在變量sfname中,目標(biāo)文件名放在變量tfname中。請在程序的ド劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。注意:源程序存放在考生文件夾下的BLANK1.C中。不得增行或刪行,也不得更改程序的結(jié)構(gòu)!給定源程序:#include<stdio.h>#include<stdlib.h>intfun(char*source,char*target){FILE*fs,*ft;charch;/**********found**********/if((fs=fopen(source,1 ))==NULL)return0;if((ft=fopen(target,"w"))==NULL)return0;printf("\nThedatainfile:\n");ch=fgetc(fs);/**********found**********/while(!feof( 2 )){putchar(ch);/**********found**********/fputc(ch,:;);ch=fgetc(fs);}fclose(fs);fclose(ft);printf("\n\n");return1;)main(){charsfname[20]="myfilel",tfname[20]=*inyfile2*;FILE*myf;inti;charc;myf=fopen(sfname,w");printf("\nTheoriginaldata:\n");for(i=l;i<30;i++){c='A'+rand()%25;fprintf(myf,"%c",c)printf("%c",c);}fclose(myf);printf("\n\n");if(fun(sfname,tfname))printf("Succeed!");elseprintf('"Fail!*);解題答案:#include<stdio.h>^include<stdlib.h>intfun(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(fs)){putchar(ch);/"""*""""*"found""*"""""*"/fputc(ch,ft);ch二fgetc(fs);}fclose(fs);fclose(ft);printf("\n\n");return1;}main(){charsfname[20]=*myfilel*,tfname[20]=*myfile2*;FILE"myf;inti;charc;myf=fopen(sfname,w");printf("\nTheoriginaldata:\n");for(i=l;i<30;i++){c=,A*+rand()%25;fprintf(myf,"%c”,c);printf("%c",c);}fclose(myf);printf('\n\n");if(fun(sfname,tfname))printf("Succeed!”);elseprintf("Fai1!");)給定程序MODII.C中函數(shù)fun的功能是:將長整型數(shù)中每一位上為偶數(shù)的數(shù)依次取出,構(gòu)成一個新數(shù)放在t中。髙位仍在髙位,低位仍在低位。例如,當(dāng)s中的數(shù)為:87653142時,t中的數(shù)為:8642。請改正程序中的錯誤,使它能得出正確的結(jié)果。注意:不要改動main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!給定源程序:^include<stdio.h>voidfun(longs,long*t){intd;longsl=l;*t=0;while(s>0){d=s%10;/"*"**"*"*"*"found*"**"****"*"/if(d%2二〇){*t=d*sl+*t;si"二!0;}/""""""""""""found""""""""""""/s\=10;))main(){longs,t;printf("\nPleaseenters:");scanf("%ld",&s);fun(s,&t);printf("Theresultis:%ld\n",t);)解題答案:#include<stdio.h>voidfun(longs,long*t){intd;longsl=l;*t=0;while(s>0){d=s%10;/************found************/if(d%2==0){*t=d*sl+*t;si"二!0;}/************found************/s/=10;}}main(){longs,t;printf("\nPleaseenters:");scanf("%ld",&s);fun(s,&t);printf("Theresultis:%ld\n",t);}函數(shù)fun的功能是:將兩個兩位數(shù)的正整數(shù)a、b合并形成一個整數(shù)放在c中。合并的方式是:將a數(shù)的十位和個位數(shù)依次放在c數(shù)的十位和千位上,b數(shù)的十位和個位數(shù)依次放在c數(shù)的百位和個位上。例如,當(dāng)a=45,b=12時,調(diào)用該函數(shù)后,c=5142。注意:部分源程序存在文件PROG1.C中。數(shù)據(jù)文件IN.DAT中的數(shù)據(jù)不得修改。請勿改動主函數(shù)main和其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入你編寫的若干語句。給定源程序:#include<stdio.h>voidfun(inta,intb,long*c)printf("Theresultis:%ld\n",c);N0N0();}voidNONO(){/?本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<10;i++){main(){inta,b;longc;voidNONO();printf("Inputa,b:");scanf("%d,%d”,&a,&b);fun(a,b,&c);printf("Theresultis:%ld\n",c);NONO():}voidNONO(){/?木函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。*/FILE*rf,*wf;inti,a,b;longc;rf=fopen(*in.dat*,"r");wf=fopen("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);}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);)參考答案:voidfun(inta,intb,long*c){*c=(a%10)*1000+(b/l0)*100+(a/10)*10+(b%10);}※※※※※※※※※※※※※※※※※※※※※※派※※第05套:是給定程序中已建立一個帶有頭結(jié)點的單向鏈表,鏈表中的各結(jié)點按結(jié)點數(shù)據(jù)域中的數(shù)據(jù)遞增有序鏈接。函數(shù)fun的功能是:把形參X的值放入一個新結(jié)點并插入到鏈表中,插入后各結(jié)點數(shù)據(jù)域的值仍保持遞增有序。請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。注意:源程序存放在考生文件夾下的BLANK1.C中。不得増行或刪行,也不得更改程序的結(jié)構(gòu)!給定源程序:解題答案:#include<stdio.h>voidfun(inta,intb,long*c)r#include<stdio.h>#include<stdlib.h>#defineN8typedefstructlist*c=(a%l0)*1000+(b/10)*100+(a/10)*10+(b%10);}{intdata;structlist*next;main(){inta,b;longc;voidNONO();printf("Inputa,b:");scanf("%d,%d",&a,&b);fun(a,b,&c);}SLIST;voidfun(SLIST*h,intx){SLIST*p,*q,*s;s=(SLIST*)malloc(sizeof(SLIST));/**********found**********/s->data=1_二
q=h;p=h->next;while(p!=NULL&&x>p->data){/**********found**********/q= 2 ;p=p->next;){SLIST*p,*q,*s;s=(SLIST*)malloc(sizeof(SLIST));/**********found**********/sー〉data二x;q=h;p二h->next;while(p!=NULL&&x>p->data){s->next=p;/**********tound**********/q->next= 3 ;)SLIST*creatlist(int*a){SLIST*h,*p,*q;inti;h=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;)p->next=O;returnh;)voidoutiist(SLIST*h){SLIST*p;p=h->next;if(p=NULL)printf(n\nThelistisNULL!\n");else{printf(M\nHeadM);do{printf("->%d',,p->data);p=p->next;}while(p!=NULL);printf(H->End\nM);)/**********found**********/q=p;p二pー〉next;)sー〉next二p;/**********found**********/qー〉next二s;)SLIST*creatlist(int*a){SLIST*h,*p,*q;inti;h=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;)p->next=0;returnh;)voidoutlist(SLIST*h){SLIST*p;p=h-〉next;if(p==NULL)printf("\nThelistisNULL!\n*);else)main(){SLIST*head;intx;inta[N]={11,12,15,18,19,22,25,29);head=creatlist(a);printf(M\nThelistbeforeinserting:\nn);outlist(head);printf(H\nEnteranumber:");scanf("%d",&x);fun(head,x);printf("\nThelistafterinserting:\nH);outlist(head);}解題答案:#include<stdio.h>^include<stdlib.h>#defineN8typedefstructlist{intdata;structlist*next;}SLIST;voidfun(SLIST*h,intx){printf("\nHead");do {printf("ー〉%d”,pー〉data); p=p-〉next;}while(p!=NULL);printf("->End\n");})main(){S
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 假期讀一本好書讀后感900字(12篇)
- 2024全新能源開發(fā)項目投資與合作合同
- 中式快餐創(chuàng)業(yè)計劃書
- 2024年工業(yè)設(shè)備維修協(xié)議
- 2024年度4S店租賃期內(nèi)公共區(qū)域維護與管理協(xié)議
- 2024年建筑工程消防設(shè)計與施工合同
- 2024年企業(yè)廣告發(fā)布與媒體投放合同
- 2024年大數(shù)據(jù)分析與應(yīng)用服務(wù)協(xié)議
- 2024年度「惠州技術(shù)開發(fā)」合同標(biāo)的:技術(shù)研發(fā)與成果共享
- 2024年工程項目混凝土供應(yīng)合同
- 2024年中儲棉總公司招聘筆試參考題庫含答案解析
- 2024年中國石油招聘筆試參考題庫含答案解析
- 臨床康復(fù)學(xué)試題及答案
- 血常規(guī)考試題庫含答案全套
- JGT215-2017 建筑門窗五金件 多點鎖閉器
- 十字頭夾具設(shè)計說明書
- 心律失常指南課件
- 2023年好醫(yī)生繼續(xù)教育公共必修課《醫(yī)務(wù)人員職業(yè)素質(zhì)修養(yǎng)與執(zhí)業(yè)法律知識》題庫
- 2023年軍隊文職考試《數(shù)學(xué)1》真題
- 長春耐火磚施工方案
- 〔部編版〕口語交際:勸告名師課件1
評論
0/150
提交評論