南昌大学C语言考试题库

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

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

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

资源描述

第1页共33页一、阅读程序写出程序运行结果阅读以下程序并写出其运行结果#includestdio.h#includestdlib.hintfun(chars[],intc){char*q=s;for(;*q;q++)if(*q!=c)*(s++)=*q;*s=0;}main(){staticcharstr[]=turbocandborlandc++;charch;fun(str,'c');printf(str[]=%s\n,str);system(pause);}程序的运行结果是str[]=turboandBorland++阅读以下程序并写出其运行结果#includestdio.h#includestdlib.hvoidfun(inta,intb,long*c){*c=a/10*10+a%10*1000+b/10*100+b%10;}main(){inta=42,b=25;longc;fun(a,b,&c);printf(Theresultis:%ld\n,c);system(pause);}程序的运行结果是theresultis:2245请按任意键继续…阅读以下程序并写出其运行结果#includestdio.hvoidfun(int*s,intnl,intn2)第2页共33页{inti,j,t;i=nl;j=n2;while(ij){t=s[i];s[i]=s[j];s[j]=t;i++;j--;}}main(){inta[10]={1,2,3,4,5,6,7,8,9,0},k;fun(a,0,3);fun(a,4,9);fun(a,0,9);for(k=0;k10;k++)printf(“%d”,a[k]);printf(“\n”);}程序运行的结果是5678901234Pressanykeytocontinue阅读以下程序并写出其运行结果#includestdio.hmain(){inti=1;while(!((i%2==1)&&(i%3==2)&&(i%5==4)&&(i%6==5)&&(i%7==0)))++i;printf(\nTheladderhas%dstages.\n,i);}程序的运行结果是阅读以下程序并写出其运行结果#includestdio.h#defineROW3#defineCOL4main(){intmatrixA[ROW][COL]={11,12,13,14,15,16,17,18,19,20,21,22};intmatrixB[COL][ROW];inti,j;printf(%d*%d:\n,ROW,COL);for(i=0;iROW;i++){for(j=0;jCOL;j++){第3页共33页matrixB[j][i]=matrixA[i][j];}}printf(MatrixB,);printf(%d*%d:\n,COL,ROW);for(i=0;iCOL;i++){for(j=0;jROW;j++){printf(%8d,matrixB[i][j]);}printf(\n);}system(pause);}程序的运行结果是3*4MatrixB4*3111519121620131721141822阅读以下程序并写出其运行结果#includestdio.h#defineN10main(){intprimes[N];intpc,m,k;printf(\nThefirst%dprimenumbersare:\n,N);primes[0]=2;pc=1;m=3;while(pcN){k=0;while(primes[k]*primes[k]=m)if(m%primes[k]==0){m+=2;k=1;}else第4页共33页k++;primes[pc++]=m;m+=2;}for(k=0;kpc;k++)printf(%4d,primes[k]);system(pause);}程序的运行结果是thefiest10primenumbersare2357111317192329阅读以下程序并写出其运行结果#includestdio.h#includestring.hvoidfun(char*s[],intn){char*t;inti,j;for(i=0;in-1;i++)for(j=i+1;jn;j++)if(strlen(s[i])strlen(s[j])){t=s[i];s[i]=s[j];s[j]=t;}}main(){char*ss[]={“bcc”,”bbcc”,”xy”,”aaaacc”,”aabcc”};fun(ss,5);printf(“%s,%s\n”,ss[0],ss[4]);}程序的运行结果是阅读以下程序并写出其运行结果#includestdio.hvoidfun(char*a,char*b){while(*a==’*’)a++;while(*b=*a){b++;a++;}}main(){char*s=”****a*b****”,t[80];fun(s,t);第5页共33页puts(t);}程序的运行结果是阅读以下程序并写出其运行结果#includestdio.hmain(){FILE*fp;inta[10]={1,2,3},i,n;fp=fopen(“dl.dat”,”w”);for(i=0;i3;i++)fprintf(fp,”%d”,a[i]);fprintf(fp,”\n”);fclose(fp);fp=fopen(“dl.dat”,”r”);fscanf(fp,”%d”,&n);fclose(fp);printf(“%d\n”,n);}程序的运行结果是阅读以下程序并写出其运行结果#includestdio.hvoidswap(int*a,int*b){int*t;t=a;a=b;b=t;}main(){inti=3,j=5,*p=&i,*q=&j;swap(p,q);printf(“%d%d\n”,*p,*q);}第6页共33页程序的运行结果是阅读以下程序并写出其运行结果intcircle(intn,intd){ints=0,m=n;while(m){s=s*d+m%d;m/=d;}returns==n;}intnum[]={232,27,851};intscale[]={2,10,16};main(){inti,j;for(i=0;isizeof(num)/sizeof(num[0]);i++)for(j=0;jsizeof(scale)/sizeof(scale[0]);j++)if(circle(num[i],scale[j]))printf(%d-(%d)isaCircleNumber!\n,num[i],scale[j]);elseprintf(%d-(%d)isnotaCircleNumber!\n,num[i],scale[j]);}程序的运行结果是答案太长不想写阅读以下程序并写出其运行结果#includestdio.h#defineNULL0int*search2(int*pa,int*pb,intan,intbn){第7页共33页int*ca,*cb;ca=pa;cb=pb;while(capa+an&&cbpb+bn){if(*ca*cb)ca++;elseif(*ca*cb)cb++;elsereturnca;/*返回在这两个数表中找到相等元素*/}returnNULL;}main(){int*vp,i;inta[]={1,3,5,7,9,13,15,27,29,37};intb[]={2,4,6,8,10,13,14,27,29,37};puts(Theelementsofarrayais:);for(i=0;isizeof(a)/sizeof(a[0]);i++)printf(%d,a[i]);puts(\nTheelementsofarraybis:);for(i=0;isizeof(b)/sizeof(b[0]);i++)printf(%d,b[i]);vp=search2(a,b,sizeofa/sizeofa[0],sizeofb/sizeofb[0]);if(vp)printf(\nThefirstsamenumberinbotharraysis%d\n,*vp);elseprintf(Notfound!\n);}程序的运行结果是阅读以下程序并写出其运行结果第8页共33页#includestdio.hmain(){inti,j;charch;i=1;while(i=5){j=1;ch='a';while(j=i){printf(%2c,ch);ch=ch+1;j++;}printf(\n);i++;}}程序的运行结果是阅读以下程序并写出其运行结果#includestdio.hrest(inta[],intn){inti,low,high,t;for(i=0,low=0,high=n-1;i=high;){if(a[i]0){t=a[i];第9页共33页a[i]=a[high];a[high]=t;high--;}elseif(a[i]==0)i++;else{t=a[i];a[i]=a[low];a[low]=t;low++;i++;}}}ints[]={8,4,0,-1,6,0,-5};main(){inti;printf(\nThearrybeforerestis:\n);for(i=0;isizeof(s)/sizeof(s[0]);i++)printf(%4d,s[i]);rest(s,sizeof(s)/sizeof(s[0]));printf(\nThearryafterrestis:\n);for(i=0;isizeof(s)/sizeof(s[0]);i++)printf(%4d,s[i]);}}程序的运行结果是thearrybeforerestis840-160-5thearryafterrestis-5-100648阅读以下程序并写出其运行结果#includestdio.h#includestring.htypedefstruct{charname[9];charsex;floatscore[2];}STU;voidf(STUa)第10页共33页{STUb={“Zhao”,’m’,85.0,90.0};inti;strcpy(a.name,b.name);a.sex=b.sex;for(i=0;i2;i++)a.score[i]=b.score[i];}main(){STUc={“Qian”,’p’,95.0,92.0};f(c);printf(“%s,%c,%2.0f,%2.0f\n”,c.name,c.sex,c.score[0],c.score[1]);}程序的运行结果是阅读以下程序并写出其运行结果#includestdio.hmain(){intx,y,z,j=0;printf(\nThepossibleplanstobuy100fowlswith100Yuanare:\n\n);for(x=0;x=20;x++)for(y=0;y=33;y++){z=100-x-y;if(z%3==0&&5*x+3*y+z/3==100)printf(%2d:cock=%2dhen=%2dchicken=%2d\n,++j,x,y,z);}}程序的运行结果是第11页共33页阅读以下程序并写出其运行结果#includestdio.hvoidfun(intx){if(x/20)fun(x/2);printf(“%d”,x);}main(){fun(3);printf(“\n”);}程序的运行结果是阅读以下程序并写出其运行结果#defineMAX(a,b)(ab)?a:bmain(){intx,y;x=25;y=56;printf(theresultis:%d

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

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

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

×
保存成功