[计算机类试卷]国家二级C语言机试(操作题)模拟试卷262及答案与解析.doc

上传人:eventdump275 文档编号:498193 上传时间:2018-11-28 格式:DOC 页数:5 大小:32KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷262及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷262及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷262及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷262及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷262及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 262及答案与解析 一、程序填空题 1 函数 fun的功能是:输出 a所指数组中的前 11个数据,要求每行输出 5个数。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1 C中。不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdio h #include stdlib h void fun(int*a, int n) int i ; for(i=0; i n; i+) *found* if(【 1】 =0) *found* printf(“【 2】 “);

2、found* printf(“ d“, 【 3】 ); main() int a100=0, i, n; n=22; for(i=0; i n; i+) ai=rand() 21; fun(a, n); printf(“ n“); 二、程序修改题 2 下列给定程序中,函数 fun的功能是:按以下递归公式求函数的值。例如,当给 n输入 5时,函数值为 18;当给 n输入 3时,函数值为 14。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 !试题程序: #include stdio h *found* fun(n) int c; *

3、found* if(n=1) c=10; else c=fun(n一 1)+2; return(c); main() int n; printf(“Enter n: “); scanf(“ d“, *单精度数 h乘以 1000后再加 5,相当于对 h中的第三位小数进行四舍五入,除以 10后将其赋给一个长整型数时就把第三位小数后的数全部截去 * return(float)tmp 100 0; *除以 100,保留 2位小数 * 【试题解析】 注意:本题要求对 h的值真正进行四舍五人运算,而不是为了输出,即不能用 prinff(“ 7 2f“, h)来直接得到结果。四舍五入算法:如果要求精确到小数点后面的第 n位,则需要对第 n+1位进行运算。方法是将该小数乘以 10的 n+1次方后加 5,然后除以 10并强制转换变量类型为整型,再将该数除以 10的n次方,同时强制转换类型为浮点型。 代码实现如下: int t; *定义整型变量 t* t=(int)(h*10n+1+5) 10; *对 h进行操作, 得到值浮点型, t取值时取整数部分。 10n+1为要扩大的倍数 * h=(noat)t 10n; *将 t缩小 10n倍,并转换成浮点型 *

展开阅读全文
相关资源
猜你喜欢
  • API PUBL 1835-1997 Study of Used Motor Oil Recycling in Eleven Selected Countries《在11个选定的国家使用的电动机润滑油的回收的研究》.pdf API PUBL 1835-1997 Study of Used Motor Oil Recycling in Eleven Selected Countries《在11个选定的国家使用的电动机润滑油的回收的研究》.pdf
  • API PUBL 2026-1998 Safe Access Egress Involving Floating Roofs of Storage Tanks in Petroleum Service (Second Edition)《安全进出石油储罐的浮顶.第2版》.pdf API PUBL 2026-1998 Safe Access Egress Involving Floating Roofs of Storage Tanks in Petroleum Service (Second Edition)《安全进出石油储罐的浮顶.第2版》.pdf
  • API PUBL 2375-1997 1996 Summary of U.S Occupational Injuries Illnesses and Fatalities in the Petroleum Industry as Reported to the American Petroleum Institute Covering U.S Petrole.pdf API PUBL 2375-1997 1996 Summary of U.S Occupational Injuries Illnesses and Fatalities in the Petroleum Industry as Reported to the American Petroleum Institute Covering U.S Petrole.pdf
  • API PUBL 2376-1998 1997 Summary of U.S Occupational Injuries Illnesses and Fatalities in the Petroleum Industry As Reported to the American Petroleum Institute Covering U.S Petrole.pdf API PUBL 2376-1998 1997 Summary of U.S Occupational Injuries Illnesses and Fatalities in the Petroleum Industry As Reported to the American Petroleum Institute Covering U.S Petrole.pdf
  • API PUBL 2377-1999 1998 Summary of U.S Occupational Injuries Illnesses and Fatalities in the Petroleum Industry As Reported to the American Petroleum Institute Covering U.S Petrole.pdf API PUBL 2377-1999 1998 Summary of U.S Occupational Injuries Illnesses and Fatalities in the Petroleum Industry As Reported to the American Petroleum Institute Covering U.S Petrole.pdf
  • API PUBL 2378-2000 1999 Survey on Petroleum Industry Occupational Injuries Illnesses and Fatalities Summary Report Aggregate Data Only《1999年石油工业因职业而受伤、疾病和死亡的总结》.pdf API PUBL 2378-2000 1999 Survey on Petroleum Industry Occupational Injuries Illnesses and Fatalities Summary Report Aggregate Data Only《1999年石油工业因职业而受伤、疾病和死亡的总结》.pdf
  • API PUBL 2380-2002 2001 Survey on Petroleum Industry Occipational Injuries Illnesses and Fatalities summary Report Aggregate Data Only .pdf API PUBL 2380-2002 2001 Survey on Petroleum Industry Occipational Injuries Illnesses and Fatalities summary Report Aggregate Data Only .pdf
  • API PUBL 2510A-1996 Fire-Protection Considerations for the Design and Operation of Liquefied Petroleum Gas (LPG) Storage Facilities (Second Edition)《船上及输油管总站、天然气加工厂、炼油厂、石油化工厂及油罐区的液.pdf API PUBL 2510A-1996 Fire-Protection Considerations for the Design and Operation of Liquefied Petroleum Gas (LPG) Storage Facilities (Second Edition)《船上及输油管总站、天然气加工厂、炼油厂、石油化工厂及油罐区的液.pdf
  • API PUBL 2524-1992 Impact Assessment of New Data on the Validity of American Petroleum Institute Marine Transfer Operation Emission Factors《使用压力.真空排放阀降低蒸发损失》.pdf API PUBL 2524-1992 Impact Assessment of New Data on the Validity of American Petroleum Institute Marine Transfer Operation Emission Factors《使用压力.真空排放阀降低蒸发损失》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1