C语言课后习题答案-第四版-谭浩强第一章#includestdio.hintmain(){printf(**************************\n\n);printf(VeryGood!\n\n);printf(**************************\n);return0;}#includestdio.hintmain(){inta,b,c,max;printf(pleaseinputa,b,c:\n);scanf(%d,%d,%d,&a,&b,&c);max=a;if(maxb)max=b;if(maxc)max=c;printf(Thelargestnumberis%d\n,max);return0;}第3章1.#includestdio.h#includemath.hintmain(){floatp,r,n;r=0.1;n=10;p=pow(1+r,n);printf(p=%f\n,p);return0;}2.#includestdio.h#includemath.hintmain(){floatr5,r3,r2,r1,r0,p,p1,p2,p3,p4,p5;p=1000;r5=0.0585;r3=0.054;r2=0.0468;r1=0.0414;r0=0.0072;p1=p*((1+r5)*5);//一次存5年期p2=p*(1+2*r2)*(1+3*r3);//先存2年期,到期后将本息再存3年期p3=p*(1+3*r3)*(1+2*r2);//先存3年期,到期后将本息再存2年期p4=p*pow(1+r1,5);//存1年期,到期后将本息存再存1年期,连续存5次p5=p*pow(1+r0/4,4*5);//存活期存款。活期利息每一季度结算一次printf(p1=%f\n,p1);//输出按第1方案得到的本息和printf(p2=%f\n,p2);//输出按第2方案得到的本息和printf(p3=%f\n,p3);//输出按第3方案得到的本息和printf(p4=%f\n,p4);//输出按第4方案得到的本息和printf(p5=%f\n,p5);//输出按第5方案得到的本息和return0;}}3.#includestdio.h#includemath.hintmain(){floatd=300000,p=6000,r=0.01,m;m=log10(p/(p-d*r))/log10(1+r);printf(m=%6.2f\n,m);return0;}4.#includestdio.hintmain(){intc1,c2;c1=197;c2=198;printf(c1=%c,c2=%c\n,c1,c2);printf(c1=%d,c2=%d\n,c1,c2);return0;}5.#includestdio.hintmain(){inta,b;floatx,y;charc1,c2;scanf(a=%db=%d,&a,&b);scanf(%f%e,&x,&y);scanf(%c%c,&c1,&c2);printf(a=%d,b=%d,x=%f,y=%f,c1=%c,c2=%c\n,a,b,x,y,c1,c2);return0;}6.#includestdio.hintmain(){charc1='C',c2='h',c3='i',c4='n',c5='a';c1=c1+4;c2=c2+4;c3=c3+4;c4=c4+4;c5=c5+4;printf(passworis%c%c%c%c%c\n,c1,c2,c3,c4,c5);return0;}7.#includestdio.hintmain(){floath,r,l,s,sq,vq,vz;floatpi=3.141526;printf(请输入圆半径r,圆柱高h∶);scanf(%f,%f,&r,&h);//要求输入圆半径r和圆柱高hl=2*pi*r;//计算圆周长ls=r*r*pi;//计算圆面积ssq=4*pi*r*r;//计算圆球表面积sqvq=3.0/4.0*pi*r*r*r;//计算圆球体积vqvz=pi*r*r*h;//计算圆柱体积vzprintf(圆周长为:l=%6.2f\n,l);printf(圆面积为:s=%6.2f\n,s);printf(圆球表面积为:sq=%6.2f\n,sq);printf(圆球体积为:v=%6.2f\n,vq);printf(圆柱体积为:vz=%6.2f\n,vz);return0;}8.#includestdio.hintmain(){charc1,c2;printf(请输入两个字符c1,c2:);c1=getchar();c2=getchar();printf(用putchar语句输出结果为:);putchar(c1);putchar(c2);printf(\n);printf(用printf语句输出结果为:);printf(%c%c\n,c1,c2);return0;}9.#includestdio.hintmain(){intc1,c2;//整型定义printf(请输入两个整数c1,c2:);scanf(%d,%d,&c1,&c2);printf(按字符输出结果:\n);printf(%c,%c\n,c1,c2);printf(按ASCII码输出结果为:\n);printf(%d,%d\n,c1,c2);return0;}#includestdio.hintmain(){charc1,c2;//定义字符型变量inti1,i2;//定义整型变量printf(请输入两个字符c1,c2:);scanf(%c,%c,&c1,&c2);i1=c1;//赋值给整型变量i2=c2;printf(按字符输出结果:\n);printf(%c,%c\n,i1,i2);printf(按整数输出结果:\n);printf(%d,%d\n,c1,c2);return0;}#includestdio.hintmain(){charc1,c2;//定义为字符型inti1,i2;//定义为整型printf(请输入两个整数i1,i2:);scanf(%d,%d,&i1,&i2);c1=i1;//将整数赋值给字符变量c2=i2;printf(按字符输出结果:\n);printf(%c,%c\n,c1,c2);printf(按整数输出结果:\n);printf(%d,%d\n,c1,c2);return0;}第四章#includestdio.hintmain(){inta,b,c;printf(请输入三个整数:);scanf(%d,%d,%d,&a,&b,&c);if(ab)if(bc)printf(max=%d\n,c);elseprintf(max=%d\n,b);elseif(ac)printf(max=%d\n,c);elseprintf(max=%d\n,a);return0;}#includestdio.hintmain(){inta,b,c,temp,max;printf(请输入三个整数:);scanf(%d,%d,%d,&a,&b,&c);temp=(ab)?a:b;/*将a和b中的大者存入temp中*/max=(tempc)?temp:c;/*将a和b中的大者与c比较,取最大者*/printf(三个整数的最大数是%d\n,max);return0;}#includestdio.h#includemath.h#defineM1000intmain(){inti,k;printf(请输入一个小于%d的整数i:,M);scanf(%d,&i);while(iM){printf(输入的数不符合要求,请重新输入一个小于%d的整数i:,M);scanf(%d,&i);}k=sqrt(i);printf(%d的平方根的整数部分是:%d\n,i,k);return0;}#includestdio.h#includemath.h#defineM1000intmain(){inti,k;printf(请输入一个小于%d的整数i:,M);scanf(%d,&i);if(iM){printf(输入的数不符合要求,请重新输入一个小于%d的整数i:,M);scanf(%d,&i);}k=sqrt(i);printf(%d的平方根的整数部分是:%d\n,i,k);return0;}#includestdio.hintmain(){intx,y;printf(输入x:);scanf(%d,&x);if(x1)/*x1*/{y=x;printf(x=%3d,y=x=%d\n,x,y);}elseif(x10)/*1=x10*/{y=2*x-1;printf(x=%d,y=2*x-1=%d\n,x,y);}else/*x=10*/{y=3*x-11;printf(x=%d,y=3*x-11=%d\n,x,y);}return0;}#includestdio.hintmain(){intx,y;printf(enterx:);scanf(%d,&x);y=-1;if(x!=0)if(x0)y=1;elsey=0;printf(x=%d,y=%d\n,x,y);return0;}#includestdio.hintmain(){intx,y;printf(pleaseenterx:);scanf(%d,&x);y=0;if(x=0)if(x0)y=1;elsey=-1;printf(x=%d,y=%d\n,x,y);return0;}#includestdio.hintmain(){floatscore;chargrade;printf(请输入学生成绩:);scanf(%f,&score);while(score100||score0){printf(\n输入有误,请重输);scanf(%f,&score);}switch((int)(score/10)){case10:case9:grade='A';break;case8:grade='B';break;case7:grade='C';break;case6:grade='D';break;case5:case4:case3:case2:case1:case0:grade='E';}printf(成绩是%5.1f,相应的等级是%c\n,score,grade);return0;}#includestdio.h#includemath.hintmain(){intnum,indiv,ten,hundred,thousand,ten_thousand,place;//分别代表个位,十位,百位,千位,万位和位数printf(请输入一个整数(0-99999):);scanf(%d,&num);if(num9999)place=5;elseif(num999)place=4;elseif(num99)place=3;elseif(num9)place=2;elseplace=1;printf(位数:%d\n,place);printf(每位数字为:);ten_thousand=num/10000;thousand=(int)(num-ten_thousand*10000)/1000;hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);switch(place){case5:printf(%d,%d,%d,%d,%d,te