admin 管理员组

文章数量: 1087139


2024年1月4日发(作者:绝对值函数的化简)

《全国计算机等级考试二级教程--C语言程序设计》课后习题答案

第一章

1.1 EXE

1.2 C OBJ EXE

1.3 顺序 选择 循环

第二章

一. 选择题

2.1 B 2.2 D 2.3 B 2.4 A 2.5 C 2.6 A 2.7 B

2.8 B 2.9 D 2.10 C 2.11 B 2.12 B 2.13 A

二. 填空题

2.14 11 12

2.15 4.2 4.2

2.16 { } 定义 执行语句

2.17 关键字 用户标记符

2.18 int float double

2.19 float a1=1; float a2=1;

2.20 存储单元

2.21 3.5

2.22 (a*b)/c a*b/c a/c*b

2.23 把常量10赋给变量s

2.24 位 1或0

2.25 8 127 0111111 -128 10000000

2.26 32767 -32768 0000

2.27 10 8 16

三. 上机改错题

2.28

#include "stdio.h"; 删除行尾的";"

main(); / * main function * / 删除")"后的";",注释中的*要紧靠“/”,即应为“/*”和“*/”

函数开始处遗失了一个“{”

float r,s ; /*/*r is radius*/,/* s is area of circuilar*/*/ 注释符号不可嵌套使用

r = 5.0 ;

s = 3.14159 * r * r ;

printf("%fn",s) 行尾遗失了“;”

函数结束处遗失了一个“}”

2.29

#include "stdio.h"

main /* main function */ main后遗失了“()”

{

float a,b,c,v; /*a,b,c are sides, v is volume of cube */

a=2.0; b=3.0; c=4.0 行尾遗失了“;”

v=a*b*c;

printf("%fn", v) 行尾遗失了“;”

}

第三章

一. 选择题

3.1 C 3.2 C 3.3 D 3.4 C 3.5 D 3.6 B 3.7 C 3.8 D 3.9 A 3.10 B

3.11 C 3.12 D 3.13 D 3.14 A 3.15 C 3.16 C 3.17 C 3.18 无答案 3.19 C 3.20 B

二. 填空题

3.21 (1)-2023500(2)i=-200,j=2500

(3)i=-200

j=2500

3.22 12 0 0

3.23 一条语句 ;

3.24 ;

3.25 100,25.81,1.89234 100 25.81 1.89234 100 25.81 1.89234

3.26 x=127,x= 127,x= 177,x= 7f,x= 127

3.27 x=127,x=127 ,x=$127 ,x=$000127,x=%06d

3.28 a=513.789215,a= 513.79,a= 513.78921500,a= 513.78921500

三. 编程题和改错题

3.29 修改后的程序如下:

main()

{

double a,b,c,s,v;

printf("input a,b,c:");

scanf("%lf%lf%lf",&a,&b,&c);

s =a*b;

v=a*b*c;

printf("a=%f,b=%f,c=%fn", a,b,c);

printf("s=%f,v=%fn",s,v);

}

3.30

#include

main()

{

int a=560,b=60;

printf("560 minute is %d hour and %d minute.n",a/b,a%b);

}

3.31

#include

main()

{

int a,b;

a=1500;b=350;

printf("a div b is : %dn",a/b);

printf("a mod b is : %dn",a%b);

}

3.32

#include

main()

{

double a,b,c,ave;

printf ("input 3 double number : n");

scanf ("%lf%lf%lf",&a,&b,&c);

printf ("%.1fn",(a+b+c)/3);

}

3.33

#include

void main()

{

int a,b,c,t;

printf("请依次输入整数a,b,c:");

scanf("%d%d%d",&a,&b,&c);

printf("n你输入的值是: a=%d,b=%d,c=%dn",a,b,c);

t=b;b=a;a=c;c=t;

printf("互换之后的值是:a=%d,b=%d,c=%dn",a,b,c);

}

第四章

一. 选择题

4.1 A 4.2 A 4.3 A 4.4 D 4.5 C 4.6 A 4.7 B 4.8 C 4.9 D 4.10 C

二. 填空题

4.11 非0 0

4.12 < > >= <=同级 == !=同级

4.13 ! && ||

4.15 !

4.16 a == b || a < c x > 4 || x < -4

4.17 1

4.18 x <= 0 1 > 0

4.19 3 2 2

4.20 *#

三. 编程题

4.21 略

4.22

#include

/* 检查日期的合法性 */

int checkdate(int year, int month, int day)

{

if(year < 1900 || year > 2023)

{

printf("输入的年份无效!n");

return 0;

}

else if(month < 0 && month > 12)

{

printf("输入的月份无效!n");

return 0;

}

else if(day <= 0 && day > 31)

{

printf("输入的日期无效!n");

return 0;

}

else

{

switch(month)

{

case 4:

case 6:

case 9:

case 11:

if(day > 30)

{

printf("输入的日期无效!n");

return 0;

}

break;

case 2:

if((year%4 == 0 && year%100 != 0) || year%400 == 0)

{

if(day > 29)

{

printf("输入的日期无效!n");

return 0;

}

}

else

{

if(day > 28)

{

printf("输入的出生日期无效!n");

return 0;

}

}

break;

}/* end of switch(m0)*/

}

return 1;

}

void main()

{

int y0, m0, d0; /* 生日 */

int y1, m1, d1; /* 当前日期 */

int years, months, days; /* 实足年龄*/

printf("请输入学生的生日:");

scanf("%d%d%d", &y0,&m0,&d0);

if(checkdate(y0, m0, d0))

{

printf("请输入当前日期:");

scanf("%d%d%d", &y1,&m1,&d1);

/*当前日期合法性检查*/

if(!checkdate(y1, m1, d1))

{

return;

}

else if(y0 > y1)

{


本文标签: 输入 遗失 函数