C语言程序设计参考答案.doc
文本预览下载声明
3.3
x1=-1,177777,ffff,65535
x2=-3,17775,fffd,65533
y1=123.456703, 123.457,123.457,123.457
y2=123.449997,1.2350e+02,123.45
x1(%4d)= -1
3.4
(1) %c
(2)%c
(3)%f
(4)%f
(5)%lu
(6)%hd
(7)%d
(8)%ld
(9)%f
(10)%Lf
3.5
(1) % 右边的值不能为0
(2)正确
(3)正确
(4)类型不匹配 x3=%Lf
(5)类型不匹配 %Lf
(6)类型不匹配 %u%lf
(7)正确
(8) 不能修改const对象
(9) 类型不匹配 %u,%c
(10)正确
3.6
-6.700000
-6
177601
123
-2 0
3.8
#includestdio.h
void main()
{
char c;
c=getchar();
if((c=0c=9))
printf(%d\n,c-0);
else if((c=Ac=F))
printf(%d\n,c-A+10);
else if((c=ac=f))
printf(%d\n,c-a+10);
else
printf(“%d\n”, c);
}
程序还可以简化
3.11
#include stdio.h
void main(void)
{
unsigned short x, m,n;
scanf(%hu %hu %hu,x,m,n);
x = x ( m – n + 1);
x = x (16 - n);
printf(%hu\n,x);
}
/*4.1 编写一个程序,输入A、B、C三个学生的考试分数,输出分数居中的那个学生名(A、B或C)及考试分数。*/
#includestdio.h
void main(void)
{
float a, b, c;
printf(input the scores of student A, B, C:\n);
scanf(%f %f %f, a, b, c);
if(a=b a=c || a=b a=c)
printf(The middle is A = %f, a);
else if(b=a b=c || b=a b=c)
printf(The middle is B = %f, b);
else
printf(The middle is C = %f, c);
}
/*4.3 编写一个程序,输入一个日期(年、月、日),计算并输出该日期是这一年的第几天。*/
#includestdio.h
void main(void)
{
int y, m, d, days = 0;
int i;
printf(input a date(year month day):\n);
scanf(%d %d %d, y, m, d);
for(i = 1; i m; i++)
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: days += 31; break;
case 2: days += 28; break;
case 4:
case 6:
case 9:
case 11: days += 30; break;
}
days += d;
if(m 2 (!(y % 4) (y % 100) || !(y % 400))) days++;
printf(the day is the %dth of the year.\n, days);
}
/*
4.4
*/
/*用if语句实现*/
#includestdio.h
void main(void)
{
float x, tax;
printf(input the wage:\n);
scanf(%f, x);
if(x
显示全部