全国计算机二级考试C语言模拟试题(一)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

11套每一套题目都是按照“填空题--改错题---编程题”顺序排列,填空题上面带有两个划线的是人工做题时候多余划线,不要理睬!!#includestdlib.h#includestdio.h#defineN10doublefun(double*x){inti,j;doubleav,y[N];av=0;/**********found**********/for(i=0;iN;i++)av+=x[i]/Nfor(i=j=0;iN;i++)if(x[i]av){/**********found**********/y[j]=x[i];x[i]=-1;__j++__;}i=0;while(iN){if(x[i]!=-1)y[j++]=x[i];/**********found**********/__i++__;}for(i=0;iN;i++)x[i]=y[i];returnav;}main(){inti;doublex[N];for(i=0;iN;i++){x[i]=rand()%50;printf(%4.0f,x[i]);}printf(\n);printf(\nTheaverageis:%f\n,fun(x));printf(\nTheresult:\n,fun(x));for(i=0;iN;i++)printf(%5.0f,x[i]);printf(\n);}改错题2#includestdio.hvoidfun(char*s,intnum[5]){intk,i=5;for(k=0;ki;k++)/**********found**********/num[k]=0;for(;*s;s++){i=-1;/**********found**********/switch(*s){case'a':case'A':{i=0;break;}case'e':case'E':{i=1;break;}case'i':case'I':{i=2;break;}case'o':case'O':{i=3;break;}case'u':case'U':{i=4;break;}}if(i=0)num[i]++;}}main(){chars1[81];intnum1[5],i;printf(\nPleaseenterastring:);gets(s1);fun(s1,num1);for(i=0;i5;i++)printf(%d,num1[i]);printf(\n);}编程题#includestdio.h3#defineM4#defineN5intfun(inta[M][N]){inttot=0,i,j;for(i=0;iN;i++){tot+=a[0][i];tot+=a[M-1][i];}for(i=1;iM-1;i++){tot+=a[i][0];tot+=a[i][N-1];}returntot;}main(){intaa[M][N]={{1,3,5,7,9},{2,9,9,9,4},{6,9,9,9,8},{1,3,5,7,0}};inti,j,y;voidNONO();printf(Theoriginaldatais:\n);for(i=0;iM;i++){for(j=0;jN;j++)printf(%6d,aa[i][j]);printf(\n);}y=fun(aa);printf(\nThesum:%d\n,y);printf(\n);NONO();}voidNONO(){/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/inti,j,y,k,aa[M][N];FILE*rf,*wf;rf=fopen(K:\\k49\\24900830\\in.dat,r);4wf=fopen(K:\\k49\\24900830\\out.dat,w);for(k=0;k10;k++){for(i=0;iM;i++)for(j=0;jN;j++)fscanf(rf,%d,&aa[i][j]);y=fun(aa);fprintf(wf,%d\n,y);}fclose(rf);fclose(wf);}2、#includestdio.h#defineN4/**********found**********/voidfun(int___t[][N]___,intn){inti,s;/**********found**********/for(i=0;in;i++){s=t[i][i];t[i][i]=t[i][n-i-1];/**********found**********/t[i][n-1-i]=___s__;}}main(){intt[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10},i,j;printf(\nTheoriginalarray:\n);for(i=0;iN;i++){for(j=0;jN;j++)printf(%d,t[i][j]);printf(\n);}fun(t,N);printf(\nTheresultis:\n);for(i=0;iN;i++)5{for(j=0;jN;j++)printf(%d,t[i][j]);printf(\n);}}改错题#includestdio.h#defineN10/************found************/intfun(inta[],intm){intlow=0,high=N-1,mid;while(low=high){mid=(low+high)/2;if(ma[mid])high=mid-1;/************found************/elseif(ma[mid])low=mid+1;elsereturn(mid);}return(-1);}main(){inti,a[N]={-3,4,7,9,13,45,67,89,100,180},k,m;printf(a数组中的数据如下:);for(i=0;iN;i++)printf(%d,a[i]);printf(Enterm:);scanf(%d,&m);k=fun(a,m);if(k=0)printf(m=%d,index=%d\n,m,k);elseprintf(Notbefound!\n);}编程题6#includestdio.hvoidfun(char*a,char*p){char*q=a;intj=0;while(*q&&qp){if(*q!='*')a[j++]=*q;q++;}while(*p)a[j++]=*p++;a[j]=0;}main(){chars[81],*t;voidNONO();printf(Enterastring:\n);gets(s);t=s;while(*t)t++;t--;while(*t=='*')t--;fun(s,t);printf(Thestringafterdeleted:\n);puts(s);NONO();}voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*in,*out;inti;chars[81],*t;in=fopen(K:\\k49\\24900830\\in.dat,r);out=fopen(K:\\k49\\24900830\\out.dat,w);for(i=0;i10;i++){fscanf(in,%s,s);7t=s;while(*t)t++;t--;while(*t=='*')t--;fun(s,t);fprintf(out,%s\n,s);}fclose(in);fclose(out);}改错题#includestdio.h#includestdlib.htypedefstructaa{intdata;structaa*next;}NODE;intfun(NODE*h){intsum=0;NODE*p;/***********found**********/p=h-next;while(p){if(p-data%2==0)sum+=p-data;/***********found**********/p=p-next;}returnsum;}NODE*creatlink(intn){NODE*h,*p,*s;inti;h=p=(NODE*)malloc(sizeof(NODE));for(i=1;i=n;i++){s=(NODE*)malloc(sizeof(NODE));s-data=rand()%16;s-next=p-next;p-next=s;p=p-next;8}p-next=NULL;returnh;}outlink(NODE*h,FILE*pf){NODE*p;p=h-next;fprintf(pf,\n\nTHELIST:\n\nHEAD);while(p){fprintf(pf,-%d,p-data);p=p-next;}fprintf(pf,\n);}outresult(ints,FILE*pf){fprintf(pf,\nThesumofevennumbers:%d\n,s);}main(){NODE*head;inteven;head=creatlink(12);head-data=9000;outlink(head,stdout);even=fun(head);printf(\nTheresult:\n);outresult(even,stdout);}编程题#includestdio.h#includestring.h#defineN80intfun(char*str){inti,j=strlen(str);for(i=0;ij/2;i++)if(str[i]!=str[j-i-1])return0;return1;}main(){chars[N];voidNONO();9printf(Enterastring:);gets(s);printf(\n\n);puts(s);if(fun(s))printf(YES\n);elseprintf(NO\n);NONO();}voidNONO(){/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/FILE*rf,*wf;inti;chars[N];rf=fopen(K:\\k49\\24900830\\in.dat,r);wf=fopen(K:\\k49\\24900830\\out.dat,w);for(i=0;i10;i++){fscanf(rf,%s,s);if(fun(s))fprintf(wf,%sYES\n,s);elsefprintf(wf,%sNO\n,s);}fclose(rf);fclose(wf);}4、#includestdio.h#includestdlib.h#defineN6typedefstructnode{intdata;structnode*next;}NODE;voidfun(NODE*h){NODE*p,*q;intt;p=h;while(p){/**********found**********/q=__p-next__;/**********found**********/while(__q__)10{if(p-dataq-data){t=p-data;p-data=q-data;q-data=t;}q=q-next;}/**********found**********/p=__p-next__;}}NODE*creatlist(inta[]){NODE*h,*p,*q;inti;h=NULL;for(i=0;iN;i++){q=(NODE*)malloc(sizeof(NODE

1 / 67
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功