1参考答案习题一1、选择题CBACD2、填空题1)main()2)main()3)有穷性、确定性、有效性、0个到多个输入、1个到多个输出4)顺序、选择、循环5)自顶向下、逐步细化、模块化设计、限制goto习题二1、选择题ACCDADDAACBBACC2、填空题1)字母、数字、下划线2)03)484)(a+b)*c/(a–c)5)-606)-167)98)6429)010)10611)12412)3.50000013)014)1615)6.63、编程题//(1)编写一个程序求各种类型数据的存储长度。#includestdio.hvoidmain(){printf(int:%dbyte\n,sizeof(int));printf(shortint:%dbyte\n,sizeof(shortint));printf(longint:%dbyte\n,sizeof(longint));printf(float:%dbyte\n,sizeof(float));printf(double:%dbyte\n,sizeof(double));printf(longdouble:%dbyte\n,sizeof(longdouble));printf(char:%dbyte\n,sizeof(char));}2#includestdio.h#defineRAT1.60934voidmain(){floatk;printf(inputthekm:);scanf(%f,&k);printf(mile:%f\n,k/RAT);}习题三1、选择题DACDDDCDCC2、解析题1)#includestdio.hvoidmain(){intx=170;floata=513.789215;printf(x=%3d,x=%6d,x=%6o,x=%6x,x=%6u\n,x,x,x,x,x);printf(x=%-3d,x=%-6d,x=%6d,x=%%6d\n,x,x,x,x);printf(a=%8.6f,a=%8.2f,a=%14.8f,a=%14.8lf\n,a,a,a,a);}结果:x=170,x=170,x=252,x=aa,x=170x=170,x=170,x=170,x=%6da=513.789185,a=513.79,a=513.78918457,a=513.789184572)#includestdio.hmain(){inta,b;floatx,y;charc1,c2;scanf(a=%db=%d,&a,&b);scanf(x=%fy=%f,&x,&y);scanf(c1=%cc2=%c,&c1,&c2);printf(a=%d,b=%d,x=%f,y=%f,c1=%c,c2=%c,a,b,x,y,c1,c2);}正确输入格式:A=3b=7x=8.5y=71.82c1=Ac2=a3、编程题1)#includestdio.hvoidmain()3{intx,y;scanf(%d%d,&x,&y);printf(商数=%d,余数=%d,x/y,x%y);}2)#includestdio.hvoidmain(){doublex,y,z,avg;scanf(%lf%lf%lf,&x,&y,&z);avg=(x+y+z)/3;printf(%.1f,avg);}习题四1、选择题CCAADCCABD2、填空题1)①a0&&b0||a0&&c0||b0&&c0②ab||ac③fabs(a)5④a=0⑤a%b!=02)①!(x0)②1③!(x=0&&x=5)3)3224)ch=’A’&&ch=’Z’ch=ch-325)x2&&x=10x-1&&x=2y=-16)a+bc&&b+ca&&a+cba==b&&c==aa==b||b==c||a==c7)x0c=x/10x!=-23、编程题1)#includestdio.hmain(){intx;printf(pleaseinputanumber:);scanf(%d,&x);if(x%2==0)printf(xisaevennumber);elseprintf(xisaoddnumber);}2)#includestdio.h4main(){intx,y;printf(pleaseinputanumber:);scanf(%d,&x);if(x-5&&x0){y=x;printf(%d,y);}elseif(x==0){y=x-1;printf(%d,y);}elseif(x0&&x10){y=x+1;printf(%d,y);}elseprintf(thenumberiserror);}3)#includestdio.hmain(){inta,m;printf(pleaseinputanumber:);scanf(%d,&a);switch(a/10){case0:case1:case2:m=1;break;case3:m=2;break;case4:m=3;break;case5:m=4;break;default:m=5;break;}printf(%d,m);}4)#includestdio.hmain(){floatprice,tax;printf(pleaseinputthepriceofproduct:);scanf(%f,&price);if(price=10000)tax=price*0.05;elseif(price=5000)tax=price*0.03;elseif(price=1000)tax=price*0.02;elsetax=0;printf(%f,tax);}5)#includestdio.hmain(){5floatscore;printf(pleaseinputthescoreofstudent:);scanf(%f,&score);if(score=85)printf(VERYGOOD);elseif(score=60)printf(GOOD);elseprintf(BAD);}6)#includestdio.hmain(){intx,y,z;printf(inputtwonumber:);scanf(%d%d,&x,&y);if(x10||x99||y10||y99)printf(inputdataerror!\n);else{z=(x/10)*1000+(y/10)*100+(x%10)*10+y%10;printf(%d\n,z);}}习题五1、选择题DCADADDBDBCADAC2、填空题1)fahrcelsius=5.0/9*(fahr-32);fahr+=step;2)i=5j=4k=63)3*i-24)y--z*=x5)8526)j++i%j==0j==i7)sumksum==kj-28)s=0p=1j=i3、改错题1)#includestdio.hmain(){intn,k;floatscore,sum,ave;/**********found**********/for(n=1;n=10;n++){sum=0.0;for(k=1;k=4;k++)6{scanf(%f,&score);sum+=score;}/**********found**********/ave=sum/4;printf(NO.%d:%f\n,n,ave);}}2)#includestdio.hmain(){inti,j,k,m;for(i=1;i=9;i++)/*********found**********/for(j=0;j=9;j++)for(k=0;k=9;k++){/*********found*********/m=100*i+10*j+k;if(m==i*i*i+j*j*j+k*k*k)printf(%d,m);}}3)#includestdio.hmain(){doubler,eps,temp;intm=1;printf(\nPleaseenteraprecision:);scanf(%lf,&eps);r=0.0;/*******found*********/temp=1;/********found********/while(temp=eps){r+=temp;temp=(temp*m)/(2*m+1);m++;}/********found********/printf(\neps=%lf,Pi=%lf\n\n,eps,r*2);}4)#includestdio.h7main(){intm=0,mix=0,n;/********found********/scanf(%d,&n);while((n=2)&&(mix10)){/*******found*********/if((n%11==0)||(n%19==0)){m=m+n;mix++;}n--;}printf(%d\n,m);}5)#includestdio.hmain(){unsignedm;intn=0,max=0,t;scanf(%d,&m);do{/*******found********/t=m%10;/*******found********/if(t==0)n++;if(maxt)max=t;/*******found********/m=m/10;}while(m);printf(\nTheresult:max=%dz=%d\n,max,n);}4、编程题1)#includestdio.hmain(){ints;floatn,t,sum;t=1;sum=0;n=1;s=1.0;while(n=100){8sum=sum+t;n=n+1;s=-s;t=s/n;}printf(sum=%10.6f\n,sum);}2)#includestdio.hmain(){inti;longintn=1;for(i=1;i=10;i++){n=n*i;printf(i%5==0?%2d!=%-10ld\n:%2d!=%-10ld,i,n);}}3)#includestdio.hmain(){intn,i,j;scanf(%d,&n);for(i=1;i=n;i++){for(j=1;j=n+i-1;j++)if(j=n-i)printf();elseprintf(*);printf(\n);}}4)#includestdio.hmain(){intm,s,i;for(m=2;m1000;m++){s=0;for(i=1;im;i++)if((m%i)==0)s=s+i;if(s==m){printf(%ditsfactorsare,m);for(i=1;im;i++)9if(m%i==0)printf(%d,,i);printf(\n);}}}5)#includestdio.hmain(){inth10,h7,h5;for(h10=0;h10=8;h10++)for(h7=0;h7=8;h7++)for(h5=0;h5=8;h5++)if(h10+h7+h5==8&&h10*10+h7*7+h5*5==53)printf(h10=%d\th7=%d\th5=%d\n,h10,h7,h5);}6)#includestdio.hmain(){intday,x1,x2;day=9;x2=1;while(day0){x1=(x2+1)*2;//第一天的桃子数是第2天桃子数加1后的2倍x2=x1;day--;}printf(thetotalis%d\n,x1);}7)#includestdio.h#includemath.hmain(){floatx,x0,f,f1;x=1.5;//可改为scanf(%f,&x);do{x0=x;f=2*x0*x0*x0-4*x0*x0+3*x0-6