资源描述:
《c语言程序设计参考答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、3.3x1=-1,177777,ffff,65535x2=-3,17775,fffd,65533y1=123.456703,123.457,123.457,123.457y2=123.449997,1.2350e+02,123.45x1(%4d)=-13.4(1)%c(2)%c(3)%f(4)%f(5)%lu(6)%hd(7)%d(8)%ld(9)%f(10)%Lf3.5(1)%右边的值不能为0(2)正确(3)正确(4)类型不匹配x3=%Lf(5)类型不匹配%Lf(6)类型不匹配%u%lf(7)正确(8)不能修改const对象(9)类型不匹配%u,%c(10)正确3.6-6.700000-61
2、77601123-203.8#includevoidmain(){charc;c=getchar();if((c>='0'&&c<='9'))printf("%d",c-'0');elseif((c>='A'&&c<='F'))printf("%d",c-'A'+10);elseif((c>='a'&&c<='f'))printf("%d",c-'a'+10);elseprintf(“%d”,c);}程序还可以简化3.11#includevoidmain(void){unsignedshortx,m,n;scanf("%hu%hu%hu",&
3、x,&m,&n);x=x>>(m–n+1);x=x<<(16-n);printf("%hu",x);}/*4.1编写一个程序,输入A、B、C三个学生的考试分数,输出分数居中的那个学生名(A、B或C)及考试分数。*/#includevoidmain(void){floata,b,c;printf("inputthescoresofstudentA,B,C:");scanf("%f%f%f",&a,&b,&c);if(a>=b&&a<=c
4、
5、a<=b&&a>=c)printf("ThemiddleisA=%f",a);elseif(b>=a&&b<=c
6、
7、b<=a&&b>
8、=c)printf("ThemiddleisB=%f",b);elseprintf("ThemiddleisC=%f",c);}/*4.3编写一个程序,输入一个日期(年、月、日),计算并输出该日期是这一年的第几天。*/#includevoidmain(void){inty,m,d,days=0;inti;printf("inputadate(yearmonthday):");scanf("%d%d%d",&y,&m,&d);for(i=1;i9、=31;break;case2:days+=28;break;case4:case6:case9:case11:days+=30;break;}days+=d;if(m>2&&(!(y%4)&&(y%100)
10、
11、!(y%400)))days++;printf("thedayisthe%dthoftheyear.",days);}/*4.4*//*用if语句实现*/#includevoidmain(void){floatx,tax;printf("inputthewage:");scanf("%f",&x);if(x<1000)tax=0.0;elseif(x<2000
12、)tax=x*0.05;elseif(x<3000)tax=x*0.1;elseif(x<4000)tax=x*0.15;elseif(x<5000)tax=x*0.2;elsetax=x*0.25;printf("thetax=%f.",tax);}/*用switch语句实现*/#includevoidmain(void){floatx,tax;printf("inputthewage:");scanf("%f",&x);switch((int)(x/1000)){case0:tax=0.0;break;case1:tax=x*0.05;break;case2:ta
13、x=x*0.1;break;case3:tax=x*0.15;break;case4:tax=x*0.20;break;default:tax=x*0.25;}printf("thetax=%f.",tax);}/*4.7*/#includevoidmain(void){charc;printf("inputastringendwithEnter:");c=getchar