您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 企业文档 > 华中科技大学标准C语言程序设计及应用习题答案
第二章一.选择题1.C2.BD3.A4.A5.D6.C7.D8.C9.A10.D11.B12.D13.C14.D15.A16.B17.A18.B100011001111二.判断题1.错2.错3.错4.错三.填空题1.B662.n1=%d\nn2=%d\n3.0四.计算1(1)x|y=0x002f(2)x^y=0x0026(3)x&y=0x0009;(4)~x+~y=0xffc6(5)x=30x0068(6)y=40x00022(1)6(2)50(3)1(4)–16(5)1(6)203(1)0(2)1(3)1(4)4(5)8(6)14(1)12(2)0(3)1(4)27(5)1(6)6(7)24(8)27(9)–295(1)0(2)1(3)1(4)–3(5)2五.程序分析题程序1b=20a=3600程序2第三章一.填空题1.s=62.963.(1)scanf(%c,&c);(2)c-32更好的答案:c-('a'-'A')2.1main(){inta,b;printf(pleaseinputa&b:);scanf(%d%d,&a,&b);printf(\nmaxis%d\n,(ab)?a:b);}2.2intmax(intx,inty);main(){inta,b,c,max;printf(pleaseinputa&b&c:);scanf(%d%d%d,&a,&b,&c);max=ab?a:b;max=cmax?c:max;printf(\nmaxis%d\n,max);}2.3main(){inti=0,sum=0;while(i=100){sum+=i;i++;}printf(1+2+3+......+100=%d\n,sum);}2.4main(){inti;inta=10,b=-3;intc;printf(%6d%6d,a,b);for(i=2;i10;i++){c=3*b+a;printf(%6d,c);a=b;b=c;}printf(\n);}2.5main(){inti;while(1){printf(pleaseinputadata(0:exit):);scanf(%d,&i);if(i==0)break;if(i%2==0)printf(thedata%disaevennumber.\n,i);elseprintf(thedata%disaoddnumber.\n,i);}}2.6#includestdio.hmain(){inti;inta=8,b=1;intsum=0;for(i=0;i10;i++){b+=3;sum+=a;a+=b;printf(a%8db:%8d\n,a,b);}printf(TheSumOfIs:%d\n,sum);}2.7#includestdio.hmain(){floatx,y;printf(pleaseinputx:);scanf(%f,&x);if(x1.0)y=x;elseif(x10)y=2*x-1;elsey=3*x-11;printf(y=%f\n,y);}2.8#includestdio.hmain(){longa,i,b,a1;while(1){printf(pleaseinputdata(1-99999):);scanf(%ld,&a);printf(a:%ld\n,a);if(a=0||a=100000)break;i=0;a1=0;while(a!=0){b=a%10;printf(%8d,b);a/=10;i++;a1=a1*10+b;}printf(\ni:%lda1:%ld\n,i,a1);}}2.9#includestdio.h#includetime.h#includestdlib.hmain(){inta,b,i,k=0;randomize();a=random(1001);/*createarandomdata(0-1000)*/for(i=0;i20;i++){printf(pleaseguessanumber:);scanf(%d,&b);if(ab){k++;printf(\n%d:Smaller,guessagain!\n,k);}elseif(ab){k++;printf(\n%d:Bigger,guessagain!\n,k);}else{printf(\nYouguessright,congraturation!);printf(\nYouhaveguessed%dtimes,k);break;}}if(k==20)printf(\nsorry,youfailed!);}2.10#includestdio.hmain(){inta,b,c;intnum;for(a=0;a10;a++){for(b=0;b10;b++){for(c=1;c10;c++){num=a*100+b*10+c;if((num%3==0)&&(a==5||b==5||c==5))printf(%8d,num);}}}printf(\n\n\n);}2.11#includestdio.hmain(){inti;inta,b;printf(pleaseinputa,b:);scanf(%d%d,&a,&b);for(i=ab?a:b;i0;i--){if(a%i==0&&b%i==0){printf(Themax=%d,i);break;}}for(i=ab?a:b;i0;i++){if(i%a==0&&i%b==0){printf(\nThemin=%d,i);break;}}2.12#includestdio.hmain(){inta,k=0;printf(pleaseinputdata:);scanf(%d,&a);while(a%2==0){a=a/2;k++;}printf(\nthenumberoffactor(2)is%d,k);}2.13main(){longi,t=1;longsum=0;for(i=1;i=10;i++){t*=i;sum+=t;printf(%ld!=%ld\n,i,t);}printf(sum:%ld\n,sum);}2.14#includestdio.hvoidmain(){inti,x=0;for(i=9;i=1;i--){x=2*(x+1);}printf(Thefirstday:%d,x);}2.15#includestdio.h#definePI3.141593main(){floatr,h;floatv;printf(pleaseinputr,h:);scanf(%f%f,&r,&h);v=1.0/3*PI*r*r*h;printf(V=%.2f,v);}2.16#includestdio.h#includemath.hmain(){longintsn=0;longintm=0,t=0;inta,n,i;printf(pleaseinputan:);scanf(%d%d,&a,&n);for(i=0;in;i++){m=m*10+a;sn+=m;}printf(a+aa+aaa+...+aa...a=%ld\n\n,sn);}2.17#includestdio.hmain(){intk;printf(pleaseinputk:);do{scanf(%d,&k);if(k=0&&k=6)break;}while(1);switch(k){case0:printf(Sunday.\n);break;case1:printf(Monday.\n);break;case2:printf(Tuesday.\n);break;case3:printf(Wednesday.\n);break;case4:printf(Thursday.\n);break;case5:printf(Friday.\n);break;case6:printf(Saturday.\n);break;}}2.18#includestdio.hmain(){inti;doublex,a,b=1,sum=1;printf(pleaseinputx:);scanf(%lf,&x);a=x;for(i=1;a/b=1e-6;i++){sum=sum+a/b;a=a*x;b=(i+1)*b;}printf(\nsum=%lf,sum);}2.19#includestdio.h#includemath.hmain(){floata,x1,x2;printf(inputa:);scanf(%f,&a);x1=1.0;while(1){x2=1.0/2*(x1+a/x1);if(fabs(x2-x1)1e-5)break;x1=x2;}printf(sqrt(a)=%f,x2);}第四章写出下列程序输出结果1.no1a=1no1a=0no1a=1no1a=02.a=0b=0c=0a=1b=0c=0a=2b=0c=03.main:x=5,y=1,n=1func:x=6,y=21,n=11main:x=5,y=1,n=11func:x=8,y=31,n=21第五章1.D2.D3.C4.65.CDABC6.(1)j+=2(2)a[i]a[j]7.(1)s[i++]!='\0'(2)s[i-1]8.D9.B10.6(同题4)11.s[i]='0'&&s[i]='9'12.(1)'\0'(2)str1[i]-str2[i]5.1#includestdio.hintfun();intfun(){inta[3][3],sum;inti,j;sum=0;/*error*/for(i=0;i3;i++){for(j=0;j3;j++)scanf(%d,&a[i][j]);/*error*/}for(i=0;i3;i++)sum=sum+a[i][i];printf(sum=%d\n,sum);}voidmain(){fun();}5.2#includestdio.hvoidmain(void){floatNum[10];floatInput,GetNum[11];inti,j;floata=6;for(i=0;i10;i++){Num[i]=a;a=a+7.5;}Loop1:printf(PleaseinputaNumber(0-80)Input=);scanf(%f,&Input);if((Input0)||(Input70)==1)gotoLoop1;for(i=0;i10;i++){if(InputNum[i])gotoLoop2;}Loop2:for(j=0;ji;j++)GetNum[j]=Num[j];GetNum[j]=Input;for(j=i;j=10;j++,i++)GetNum[j+1]=Num[i];for(j=0;j11;j++)printf(%3.3f,GetNum[j]);}5.3#includestdio.h#includestdlib.hmain(){inta1,a2,a3,a4,a5,a6,a7,a8,a9;inta[3];inti;for(;;){for(i=0;i3;i++){a[i]=rand()%3;}while((a[0]!=a[1])&&(a[0]!=a[2])&&(a[1]!=a[2]))/*getthreedifferentnumbers0,1,2*/{a1=a[0]+1;/*divide1~9intothreegroups,a1~a3,a4~a6,a7~a9*/a2=a[1]+1;a3=a[2]+1;a4=a1+3;a5=a2+3;a6=a3+3;a7=a1+6;a8=a2+6;a9=a3+6;/*makesurethateachlineandeachrowismadeupwiththreemembersindiffe
本文标题:华中科技大学标准C语言程序设计及应用习题答案
链接地址:https://www.777doc.com/doc-2643168 .html