C语言程序设计实验与习题指导同步自测答案

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

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

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

资源描述

C语言程序设计实验与习题指导同步自测答案2.1.3同步自测一、选择题1.D2.C3.D4.C5.A6.B7.D8.C二、填空题1.①c②exe2.①main3.①函数说明部分②函数体4.①主或main②主或main5.①;2.2.3同步自测一、选择题1.B2.D3.C4.C5.C6.B7.D8.A9.C10.B11.D12.D13.D14.C15.C16.D17.C18.C19.B20.A21.D22.A23.D24.C25.D26.B27.B28.D29.D30.C31.A32.B33.D34.B35.C2.3.3同步自测一、选择题1.B2.C3.D4.A5.B6.A7.A8.A9.D10.B2.4.3同步自测一、选择题1.B2.A3.B4.C5.B6.D7.C8.A9.D10.B二.编程题1.#includestdio.hvoidmain(){intx,y;printf(请输入自变量x的值:);scanf(%d,&x);if(x0)y=3*x+1;elseif(x5)y=2*x;elsey=x+2;printf(\n函数y的值为:%d,y);}2.#includestdio.hvoidmain(){inta,b,c,d,t;printf(请输入四个整数:\n);scanf(%d%d%d%d,&a,&b,&c,&d);if(ab){t=a;a=b;b=t;}if(ac){t=a;a=c;c=t;}if(ad){t=a;a=d;d=t;}if(bc){t=b;b=c;c=t;}if(bd){t=b;b=d;d=t;}if(cd){t=c;c=d;d=t;}printf(按新顺序输出的数为:%d%d%d%d,a,b,c,d);}2.5.3同步自测一、选择题1.C2.C3.D4.D5.D6.C7.D8.B9.A10.B11.B12.B13.B14.B15.C二、填空题1.①getchar()2.①n++3.①′\n′②num++;4.①n=m②total=total+sum5.①(i/100)*(i/100)*(i/100)+((i/10)%10)*((i/10)%10)*((i/10)%10)+(i%10)*(i%10)*(i%10)②g==i6.①107.①i%j==08.①b9.①y=1②x%i==010.①2*x+4*y==90三.读程序写结果题1.8,172.57233.4四.编程题1.main(){intx,y,a,b;for(x=100;x1000;x++){y=0;a=x;while(a){y=y*10+a%10;a=a/10;}if(x+y==1333)printf(a=%d;b=%d;c=%d\n,x/100,(x/10)%10,x%10);}}2.main(){longx,y/*存放x*/,n/*记录x的位数*/,s/*存放x*x*/;longz/*存放被取的顺序从右到左的相应部位数字*/,t/*十进制的权*/;for(x=1;x=100;x++){y=x;n=0;z=0;t=1;while(y){n++;/*记录x的位数*/y=y/10;}s=x*x;for(;n0;n--){z+=(s%10)*t;/*取相应部位数字*/t*=10;s=s/10;}if(x==z)printf(%-10ld,x);}}3.main(){inti;for(i=1;i=100;i++)if((i+3)%5==0&&(i-3)%6==0){printf(%d,i);break;}}4.main(){intx,a,b,c;for(x=100;x1000;x++){a=x/100;b=(x/10)%10;c=x%10;if(a*a*a+b*b*b+c*c*c==1099)printf(%-10d,x);}}5.main(){intx,a,b,c,count=0;for(x=100;x1000;x++){a=x/100;b=(x/10)%10;c=x%10;if(a+b+c==5)count++;}printf(共有%d个其各位数字之和是5的数字,count);}2.6.3同步自测一、选择题1.B2.C3.D4.B5.A6.D7.D8.D9.D10.B11.B12.A13.D14.D15.B16.B17.A18.A19.B20.A21.A22.D23.D24.A25.A二、填空题1.①fac(n-1)2.①a*a%8!=13.①a%b4.①i++5.①j!=0或j②n%10+’0’6.①x=’a’&&x=’z’7.①x=n②n%10③x三、读程序写结果题1.9,192.f=63.1235.306.-5,-12,-77.10,20,308.!EDCBA9.432110.711.213.5,2517.15,14518.6四、编程题1.#includestdio.hvoiddelspace(char*s){inti,j;for(i=0,j=0;s[i]!=’\0’;i++)if(s[i]!=’’){s[j]=s[i];j++}4.12312.17,7,717,8,1114.1,7,310,7,31,7,410,7,46,7,415.12345633-22,5,1123,45616.j=2S=10s[j]=’\0’;}voidmain(){char*str;printf(“inputstring:”);gets(str);delspace(str);printf(“%s”,str);}3.#includestdio.h#includemath.hvoidmain(){intisprime(intx);inta;printf(“pleaseinputthenumber:\n”);scanf(“%d”,&a);if(isprime(a))printf(“the%disaprime\n”,a);elseprintf(“the%disnotaprime\n”,a);}intisprime(intx){intj;for(j=2;j=sqrt(x);j++)if(x%j==0)return0;return1;}2.7.3同步自测一、选择题1.C2.A3.C4.A5.D6.C7.C8.D9.B10.B11.D12.C13.D14.D15.B二、填空题1.①k=p2.①a[i][j]min3.①i+j==24.①continue5.①j=3②a[j-1][k-1]6.①x/10或int(x/10)7.①!(s[i]=’0’&&s[i]=’9’)8.①a[n-i-1]=temp三、读程序写结果题1.max=10,row=2,colum=12.18,103.countryside4.xbcdBCD四、编程题1.参考程序及评分标准一:#includestdio.h#defineN52.#includestdio.h#includemath.hvoidmain(){intadddigit(intnum);intn;scanf(“%d”,&n);printf(“sum=%d\n”,addigit(n));}intaddigit(intnum){ints=0;num=abs(num);do{s+=num%10;num/=10;}while(num);returns;}viodmain(){inta[N+1],x,i,k;for(i=0;iN;i++)scanf(%d,&a[i]);scanf(%d,&x);//2分for(i=0;a[i]x&&iN;i++);//3分for(k=N;ki;k--)a[k]=a[k-1];a[i]=x;//3分for(i=0;i=N;i++)printf(%5d,a[i]);putchar(‘\n’);//2分}参考程序及评分标准二:#includestdio.h#defineN5viodmain(){voidinsert(intv[],intn,intx);inta[N+1],x,i;for(i=0;iN;i++)scanf(%d,&a[i]);scanf(%d,&x);//2分insert(a,N,x);//2分for(i=0;i=N;i++)printf(%5d,a[i]);putchar(‘\n’);//2分}voidinsert(intv[],intn,intx){inti,k;for(i=0;v[i]x&∈i++);//2分for(k=N;ki;k--)v[k]=v[k-1];v[i]=x;//2分}3.#includestdio.h#includestring.hvoidmain(){voidcopystr(char*p1,char*p2,intm);charstr1[20],str2[20];scanf(“%s”,str1);scanf(“%d”,&m);if(strlen(str1)m)printf(“inputerror”);else{copystr(str1,str2,m);printf(“theresultis:%s”,str2);}}voidcopystr(char*p1,char*p2,intm){intn=0;while(nm-1){n++;p1++;}while(*p1!=’\0’){*p2=*p1;p1++;p2++;}*p2=’\0’;}2.9.3同步自测一、选择题1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.2.#includestdio.h#includestring.hvoidmain(){voidreverse(chars[]);chars1[80];gets(s1);reverse(s1);puts(s1);}voidreverse(chars[]){inti,j,c;for(i=0,j=strlen(s)-1;ij;i++,j--){c=s[i];s[i]=s[j];s[j]=c;}}

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

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

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

×
保存成功