第2章课后习题参考答案
一、(略)
二、单选题
1、C 2、D 3、C 4、A 5、C 6、D 7、C 8、B 9、D 10、A
三、填空题
1、 1 2、 880 3、 4 5 6、 3 .500000 0
四、写程序运行结果
1、 2,1 2、 0 3、 16 4、3 5、 1
五、编程题
解:设鸡有X只,兔有Y只,根据题意可得方程如下:
x+y=a
2x+4y=b
解方程组可得到:
x=(4*a-b)/2
y=(b-2a)/s
编程如下:
#include
#include
main( )
{
int x,y,a,b;
printf(“Please input two interger numbers:\n”);
scanf(“%d,%d”,&a,&b);
x=(4*a-b)/2;
y=(b-2*a)/2;
printf(“There are %d chicken.\n”,x);
printf(“There are %d rabbit.\n”,y);
}
2、(题意看书上:求三角形面积)
#include
#include
main( )
{int a,b,c;
float s ,area;
printf(“Please input 3 numbers for triangle:\n”);
scanf(“%d,%d,%d”,&a,&b,&c);
s=0.5*(a+b+c);
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf(“area=%f”,area);
}
第3章课后习题参考答案
单选题
B 2、B C 3、A 4、D 5、B 6、C
7、C 8、C 9、A 10、A 11、C 12、C 13、B 14、C 15、B 16、B
写出下列程序的运行结果
1、 a=20,b=40,c=20 2、 23 3、68 4、a=%d ,b=%d 5、 1 65 1.5 6.5
6、a=3.140000,3.1400000e+00,3.140e+00,3.140e+00
b=-3.141,-3.1415e+00,-3.1415e+00
7、x=4 y=11 8 k=4 9 x=4.900000 y=4 10 *
**
***
****
填空题
1、 (1) d,e (2) (a>b) (3) (d>c) 输出显示:max=7
2、 (1)k=1;break;(2)k=2;break;(3)k=3;break;(4)k=4;break;(5)k=5;break;
3 4、(i%3==0)&&(i%5==0)&&(i%7==0) 5、i=0,j=0,n; scanf(“%d”,&n);
四、编程题
1.要求从大到小打印三个整数,a,b,c.
main()
{
int a,b,c,t;
scanf("%d%d%d",&a,&b,&c);
if(a
{ t=a; a=b; b=t;}
if(a
{ t=a; a=c; c=t;}
if(b
{ t=b; b=c; c=t;}
printf("big to small:%d %d %d\n",a,b,c);
}
2.编程求一元二次方程的根
#include
main()
{
float a,b,c,disc,x1,x2,realpart,imagpart;
printf("input canshu a,b,c");
scanf("%f,%f,%f",&a,&b,&c);
printf("The equation ");
if(fabs(a)<=1e-6)
printf("is not a 2 ci fangcheng.");
else
disc=b*b-4*a*c;
if(fabs(disc)<=1e-6)
prin