已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
自测练习奇数题答案第1章1.1节1软件1.2节1存储单元0:75.625存储单元2:0.005存储单元999:75.623位,字节,存储单元,主存储器,辅助存储器,LAN,WAN1.3节1a、b、c的值相加,把和存储到x;y除以z,将结果存储到x;c减b,然后加a,将结果存储到d;z加1,并将结果存储到z;celsius加273.15,并将结果存储到kelvin。3源程序,编译器,编辑器(字处理器)1.4节1问题需求,分析,设计,实现,测试和验证,维护1.5节1算法细化(1) 获得以公里表示的距离。(2) 把距离转化成英里。 2.1 用英里表示的距离是用公里表示的距离的0.621倍。(3) 显示用英里表示的距离。第2章2.1节1a. void, double, returnb. printfc. MAX_ENTRIES, Gd. time, xyz123, this_is_a_long_onee. Sues, part#2, char, #include3预处理器,#define和#include2.2节1a. 0.0103 .0 123450.0b. 1.3e+3 1.2345e+2 4.26e-33double, int, char2.3节1Enter two integers 5 7m = 10 n = 21 3My name is Jane Doe.I live in Ann Arbor, MIand I have 11 years of programming experience.2.4节1/* This is a comment? */* This one seems like a comment doesnt it */2.5节1a. 22/7为3 7/22为0 22 % 7为1 7 % 22为7b. 16 / 15 为1 15 / 16为0 16 % 15为115 % 16为15c. 23 / 3 为7 3 / 23为0 23 % 3为2 3 % 23为3d. 16 / -3 为? -3 / 16为? 16 % -3为? -3 % 16为? (?意为结果是变化的)3a. 3 g. 未定义 m. -3.14159b. ? h. 未定义 n. 1.0c. 1 i. ? o. 1d. -3.14159 j. 3 p. 未定义e. ? k. -3.0 q. 3f. 0.0 l. 9 r. 0.75(?意为结果是变化的)5a. white为1.6666 c. orange为0 e. lime为2 b. green为0.6666 d. blue为-3.0 f. purple为0.02.6节1printf(Salary is %10.2fn,salary);3xis12.34iis100iis100xis12.32.7节1在调用scanf获得数据之前先调用printf显示提示。当调用scanf后有数据回应时调用printf。提示用于交互式程序而不用于批处理程序。批处理程序应该回显输入,交互程序也可以回显输入。第3章3.1节1问题输入double hours /* number of hours worked */double rate /* hourly rate of pay */ 问题输出double gross /* gross salary */ 算法(1) 输入工作时间hours和每小时所付的工资率rate。(2) 计算总工资gross。 2.1把hours * rate的值赋给gross。(3) 显示总工资gross。3问题输入double reg_hours /* number of regular hours worked */double ot_hours /* number of overtime hours worked */double rate /* hourly rate of pay */ 问题输出double gross /* gross salary */ 算法(1) 输入常规工作时数(reg_hours)、加班时数(ot_hours)和每小时所付工资比率rate。(2) 计算总工资gross。2.1 将reg_hours * rate的值赋给gross。2.2 前一步gross的值再加上ot_hours * 1.5 * rate。(3) 显示总工资gross。3.2节1a. sqrt(u + v) * pow(w,2) b. log(pow(x,y) c.sqrt(pow(x y, 3) d. fabs(x * y w / z)3.3节1设计阶段3.4节1HI MOM被用较大的印刷体字母垂直地输出。3.5节1a. 3141.590000 b. 31.415900 c.* * * * 31.42 * * * * d. 3.141590 e. 3.1415903函数参数被用来在一个程序的各个模块之间、主程序与其模块之间传递信息。参数使函数更容易被其他函数或程序复用。带参数的函数是建造更大程序的基石。第4章4.2节3x = 3.0 y = 4.0 z = 2.0 flag = 0 ! ( flag | ( y + z = x z ) 0 4.0 2.0 3.0 2.0 6.0 1.0 1 1 011(TRUE) 0(FALSE) 1(TRUE) 1(TRUE)5ans为2。4.3节1a. not lessb. greater than4.4节1. if (x y ) x = x + 10.0; printf(x Biggern); else printf(x Smallern); printf(y is %.2fn,y); 3. if (engine_type = J) printf(Jet engine); speed_category = 1; else printf(Propellers); speed_category = 2; 4.5节1额外的程序常量:CAP_GALLONS 100 /* maximum number of gallons (in thousands) for basic fee */ 额外的程序变量:int excess /* number of gallons over CAP_GALLONS */ comp_use_charge的改写算法:(1) used 为 current previous(2) if used CAP_GALLONS excess 为 used GAP_GALLONS use_charge 为 CAP_GALLONS * PRE_1000_CHG + excess * PER_1000_CHG * 2 else use_charge 为 used * PER_1000_CHG4.7节1. 语句部分工 资税结 果if (salary 0.0 )23500.00?23500.00 0.00 为假else if (salary 15000.00 )23500.00 15000.00 为假else if (salary 30000.00 )23500.00 7 ) if (pH 2) printf(Acidic); else printf(Very acidic);4.8节1. red blue yellow第5章5.1节1a. 计数循环(1) 初始化sum为0。(2) 设置lcv为0。(3) while lcv100, count加1; (5) 获得下一个温度并存储输入状态。5.2节10 10 1 9 2 8 3 7 4 6 5 55.3节1a. Enter an integer 5 5 25 125 625 b. Enter an integer 6 6 36 216 1296 c. Enter an integer 7 7 49 343 2401 一般地,该循环显示n,n2,n3和n4。3count = 0; sum = 0; while (count ); scanf(%d, &next_num); sum += next_num; count += 1; printf(%d numbers were added; , count); printf(their sum is %d.n,sum);5.4节1当n = 8时:语 句addsum作 用sum = 0; 0初始化sum为0odd = 1; 1初始化odd为1odd n; 18为真sum += odd; 1sum = 0 + 1odd +=23odd = 1 + 2odd n; 38 为真sum += odd; 4sum = 1 + 3odd +=25odd = 3 + 2odd n; 58 为真sum +=odd; 9sum = 4 + 5odd +=27odd = 5 + 2odd n; 78为真sum += odd; 16sum = 9 + 7odd += 29odd = 7 + 2odd n; 98 为假退出循环printf(Sum ofOutput: Sum of positive odd numbers less than8 is 16.3两个问题的答案都为0。5+i -j; n = i * j; m = i + j; j-; p = i + j;7. a. 1 10 2 8 3 6 4 4 5 2 b. j = 10; for ( i = 0; i 8350.8 8350.80 barrels are available. Enter number of gallons removed 7581.0 After removal of 7581.00 gallons (180.50 barrels), 8170.30 barrels are available. Enter number of gallons removed 7984.2 After removal of 7984.20 gallons (190.10 barrels), Only 7980.20 barrels are left. * WARNING * Available Supply is less than 10 percent of tanks 80000.00-barrel capacity.5.6节1步骤a初始化循环控制变量。 步骤c循环重复的条件。 步骤e循环控制变量的更新。5.7节1a. * * * * * b. * * * * *5.8节1while循环较好,因为do-while在每次迭代时对相同的条件检测两次。5.9节1for (status = fscanf(hdd_file, %d, &next_hdd); status = 1; status = fscanf(hdd_file, %d,&next_hdd) if (next_hdd heat_deg_days) heat_deg_days = next_hdd; coldest_mon = ct; +ct; 5.10节1for ( count = 0; count = n; +count) printf(DEBUG* * * count = %dn, count); sum += count; printf(DEBUG* * * sum = %dn, sum); 第6章6.1节1. void sum_n_avg(double n1, /* input numbers */ double n2, double n3, double *sump, /* output sum of the three numbers */double *avgp) /* output average of the numbers */3引 用何处合法数据类型值&manymain int *指向带灰底的单元valpsubdouble *指向带灰底的单元codemaincharg&codemainchar *指向不带底纹的单元countpsubint *指向带网格的单元*countpsubint14*valpsubdouble17.1letpsubchar *指向不带底纹的单元&xmaindouble *指向带灰底的单元6.2节1函数调用num1num2num3order(&num3, &num2);81210order(&num2, &num1);128order(&num3, &num2);108对函数order的这种调用顺序将num1、num2、num3变成降序(从最大到最小)。6.4节1void onef(int dat, int *outlp, int *out2p) int tmp; twof(dat, &tmp, out2p); . void twof(int indat, int *result1p, int *result2p)6.5节1因为有很多值需要返回,这只能通过使用输出参数实现。第7章7.1节1表示误差出现在当一个double类型变量的尾数包含的位(二进制位)数不足以精确表示某个分数时;抵消误差发生在当两个在数量上相差悬殊的数进行某种运算时,其结果是较小的数丢失。3 x y m n10.5 7.2 5 2a. x / (double)m 2.1b. x / m 2.1c. (double)(n * m) 10.0d. (double)(n / m) + y 7.2e. (double)(n / m) 0.07.2节1a. 3 b. E c. -17.3节1typedef enum monday, tuesday, wednesday, thursday, friday, saturday, sunday dat_t; a.0 b.3 c.0(FALSE) d.friday e.wednesday f.1(TRUE)7.4节12.0.3.0就是一个这样的区间。第8章8.1节1x3是一个有效的变量名,x3是对数组x第4个元素的引用。3double sq_root11; int cube11;1之前 8.2节x0x1x2x3x4x5x6x716.012.06.08.02.512.014.0-54.5之后 x0x1x2x3x4x5x6x716.012.06.08.012.014.014.0-54.58.3节1#include #define MAX_SIZE 11 . double cubeMAX_SIZE; int sq_rootMAX_SIZE; int i; for (i = 0; i MAX_SIZE; +i) sq_rooti = sqrt(double)i); cubei = i * i * i; 8.4节1seg_len = sqrt(pow(xi+1 xi, 2) + pow(yi+1 yi, 2);3sum = 0; for (i = 0; i LIST_SIZE; i += 2) sum += listi;8.5节1如果一个数组的几个元素都被某个函数处理,传递整个数组数据比传递单个的元素更好。3/* * Gets data to place in dbl_arr until value of sentinel * is encountered in the input. * Returns number of values stored through dbl_sizep. * Stops input prematurely if there are more than dbl_max data * values before the sentinel or if invalid data is encountered. * Pre: sentinel and dbl_max are defined and dbl_max * is the declared size of dbl_arr * Post: returns 1 for no error, and 0 for any error conditions. */intfill_to_sentinel(int dbl_max, /* input declared size of dbl_arr */ double sentinel,/* input end of data value in input list */ double dbl_arr,/* output array of data */ int *dbl_sizep)/* output number of data values stored in dbl_arr */ double data; int i, status; int result = 1; /* Sentinel input loop */ i = 0; status = scanf(%lf,&data); while (status = 1 & data != sentinel & i dbl_max) dbl_arri = data; i+; status = scanf(%lf,&data); /* Issues error message on premature exit */ if (status != 1) printf(n* Error in data format *n); printf(* Using first %d data values *n, i); result = 0; else if (data != sentinel) printf(n* Error: too much data before sentinel *n); printf(* Using first %d data values *n, i); result = 0; /* Sends back size of used portion of array, and error status */ *dbl_sizep = i; return (result); 5.| | $ | $ - | $ ch is -.8.6节1a.n-1作为匹配的位置返回。 b. 第一个匹配的位置被返回。3为实现降序排序,用index_of_max代替所出现的每个index_of_min,用largest代替所有的smallest来改写选择排序算法。8.7节1a. int i, j, k; for (i = 0; i MAXCRS; +i) printf(Processing course number %d: n, i); for (j = 0; j 5; +j) printf( Campus %dn, j); for (k = 0; k ); break; case 1 : printf(Sophomores ); break; case 2 : printf(Juniors ); break; case 3 : printf(Seniors ); break; scanf(%d, &enrollijk); b. int i, j, jcnt; /* Number of juniors. */ jcnt = 0; for (i = 0; i MAXCRS; +i) for (j = 0; j = 0 & rank = 0 & course MAXCRS) for (i = 0; i 5; +i) cnt += enrollcourseirank; else cnt = -1; return (cnt); 用 printf(Number of sophomores in course 2 is %dn, find_students(enroll, 1, 2); d. int i, j, total, upper; total = 0; upper = 0; for (j = 0; j 5; +j) for (i = 0; i MAXCRS; +i) upper += enrollij2 + enrollij3; printf(Number of upperclass students on campus ); printf(%d is %d.n, j, upper); total += upper; printf(Total upperclass students on all campuses is %d.n,total);8.8节1. a. sales1fall, sales1winter, sales1spring, sales1summer b. sales0spring, sales1spring, sales2spring, sales3spring, sales4spring c. sales0fall, sales1fall, sales2fall, sales3fall, sales4fall sales0winter, sales1winter, sales2winter, sales3winter, sales4winter sales0spring, sales1spring, sales2spring, sales3spring, sales4spring sales0summer, s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026-2027学年上学期单元测试高二生物模拟卷及答案
- 2025茶艺师茶艺基础考点速记题及答案
- 铝电解电容器:新能源车储能和 AI 算力服务器电源扩容拉动高压大容量铝电解电容器需求增长
- 2025GMAT语文押题卷及答案
- 机械装配工艺优化手册
- 房地产经纪行业客户关系管理标准评估手册
- 系统升级部署时间表确认函4篇范文
- 合同签署进度跟进回复函(5篇)范文
- 建筑施工安全检查标准应用手册
- 市场调研中的问卷调查设计手册
- 高甘油三酯血症管理专家共识(2025版)
- 2026年行测类题库及答案详解
- 东航校招的在线测评题目2026
- 三年级语文上册人教版《大自然的声音》
- 2026语文新教材 1第24课《我将无我不负人民》
- 2026安徽省考评员培训考试题库及答案
- 2026年四川省拟任乡科级领导干部任职资格试题及参考答案
- 统编五年级上册《航天员写给孩子的信》课件
- 2026年陕西水务发展建设集团第三工程有限公司招聘(28人)考试备考试题及答案详解
- 2026年高校审计处岗招聘笔试真题附答案
- 安徽省黄山市屯溪四中2025年七年级上学期地理期中考试(含答案)
评论
0/150
提交评论