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

上传人:proposalcash356 文档编号:498603 上传时间:2018-11-29 格式:DOC 页数:6 大小:30KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷631及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷631及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷631及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷631及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷631及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 631及答案与解析 一、程序填空题 1 使用 VC+2010打开考生文件夹下 blank1中的解决方案。此解决方案的项目中包含一个源程序文件 blank1 c。在此程序中,函数 fun的功能是:将形参 n中,各位上为偶数的数取出,并按原来从高位到低位的顺序组成一个新数,作为函数值返回。 例如,从主函数输入一个整数 27638496,则函数 返回值为 26846。请在程序的下画线处填入正确的内容并将下画 线删除,使程序得出正确的结果。注意:部分源程序给出如下。 不得增行或删行,也 不得更改程序的结构 ! 试题程序: #include stdio h uns

2、igned long fun(unsigned long n) unsigned long x=0, s, i; int t; s=n; *found* i=【 1】 ; *found* while(【 2】 )t=s 10; if(t 2=0) *found* x=x+t*i; i=【 3】 ; s=s 10; return x; main() unsigned long n=-1; while(n 99999999|n 0) printf(“Please input(0 n 100000000): “); scanf(“ ld“, &n); printf(“ nThe result is:

3、 ld n“, fun(n); 二、程序修改题 2 使用 VC+2010打开考生文件夹下 modi1中的解决方案。此解决方案的项目中包含一个源程序文件 modi1 c。此程序给定函数中,函 数 fun的功能是:统计字符串中各元音字母 (即 A、 E、 I、 O、 U)的个数。注意:字母不分大小写。 例如,输入 ”THIs is a boot”,则应输出是 1 0 2 2 0。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 NODI1 C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include stdlib h #include c

4、onio h #include stdio h *found* fun(char*s, int num5) int k, i=5; for(k=0; k i; k+) *found* numi=0; for(; *s; s+) i=-1; *found* switch(s) casea: caseA: i=0; break; caSee: caseE: i=1; break; caSei: caseI: i=2; break; case0: case0: i=3; break; caseu: caseU: i=4; break; if(i =0) numi+; void main() char

5、 s181; int num15, i; system(“CLS“); printf(“ nPlease enter a string: “); gets(s1); fun(s1, hum1); for(i=0; i 5; i+) printf(“ d“, humli); printf(“ n“); 三、程序设计题 3 使用 VC+2010打开考生文件夹下 prog1中的解决方案。此解决方案的项目中包含一个源程序文件 prog1 c。在此程序中,编写函数 fun,其功能是:将两个两位数的正整数 a、 b合并成一个整数放在 c中。合并的方式是:将 a数的十位和个位数依次放在 c数的个位和百位上,

6、 b数的十位和个位数依次放在 c数的千位和十位上。 例如,当 a=45, b=12时,调用该函数后, c=1524。 注意:部分源程序给出如下。数据文件 IN DAT中的数据不得修改。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中 填入你编写的若干语句。 试题程序: #include conio h #include stdio h void fun(int a, int b, long*c) main() int a, b; long C; printf(“Input a, b: “); Scanf(“ d d“, &a, &b); fun(a, b, &c);

7、 printf(“The result is: ld n”, c); 国家二级 C语言机试(操作题)模拟试卷 631答案与解析 一、程序填空题 1 【正确答案】 (1)1 (2)s 0 (3)i*10 【试题解析】 填空 1:变量 i用来控制被取出的偶数在新数中的位置,应赋初值1。 填空 2: while语句的循环条件是 s 0。 填空 3:变量 i用来标识个位、百位和千位等。 二、程序修改题 2 【正确答案】 (1)void fun(char*s, int num5) (2)numk=0; (3)switch(*s) 【试题解析】 switch语句说明如下: (1)switch后的表达式,可

8、以是整型或字符型,也可以是枚举类型。在新的 ANSIC标准中允许表达式的 类型为任何类型。 (2)每个 case后的常量表达式只能是由常量组成的表达式,当 switch后表达式的值与某一个常量表达式的值一致时,程序就转到此 case后的语句开始执行。如果没有一个常量表达式的值与 switch后的值一致,就执行 default后的语句。 (3)各个 case后的常量表达式的值必须互不相同。 (4)各个 case的次序不影响执行结果,一般情况下,尽量将出现概率大的 case放在前面。 (5)在执行完一个 case后面的语句后,程序会转到下一个 case后的语句开始执行,因而必须使用 break语句

9、才能跳出 。 三、程序设计题 3 【正确答案】 void fun(int a, int b, long*c) *b 10获取 b的个位, a 10获取 a的十位, a 10获取 a的个位, b 10获取 b的十位 * *c=a 10+(b 10)*10+(a 10)*100+(b 10)*1000; 【试题解析】 本题主要的问题是如何取出 a和 b的个位数和十位数,取出后如何表示成 c中相应的位数。由于 a和 b都是只有两位的整数,所以分别对它们除以10可得到它们的十位数,分别用 10对它们求余可得到它们的个位数。得到后对 应乘以 1000、 100、 10、 1即可得到 c的千位数、百位数、十位数和个位数。注意使用 c时要进行指针运算。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 2591-D4-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D4 - Transverse Load (External Bending Moment) Issue P 1《航空航天系列.光电连接元件 试验方法.pdf AECMA PREN 2591-D4-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D4 - Transverse Load (External Bending Moment) Issue P 1《航空航天系列.光电连接元件 试验方法.pdf
  • AECMA PREN 2591-D5-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D5 - Axial Load Issue P 1《航空航天系列.光电连接元件 试验方法 D5部分 轴向-载》.pdf AECMA PREN 2591-D5-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D5 - Axial Load Issue P 1《航空航天系列.光电连接元件 试验方法 D5部分 轴向-载》.pdf
  • AECMA PREN 2591-D6-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D6 - Mechanical Endurance Issue P 1《航空航天系列.光电连接元件 试验方法 D6部分 机械寿命》.pdf AECMA PREN 2591-D6-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D6 - Mechanical Endurance Issue P 1《航空航天系列.光电连接元件 试验方法 D6部分 机械寿命》.pdf
  • AECMA PREN 2591-D7-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D7 - Durability of Contact Retention System and Seals (Maintenance Ageing) .pdf AECMA PREN 2591-D7-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D7 - Durability of Contact Retention System and Seals (Maintenance Ageing) .pdf
  • AECMA PREN 2591-D8-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D8 - Mating and Unmating Forces Issue P 1《航空航天系列.光电连接元件 试验方法 D8部分 啮合和非啮合力》.pdf AECMA PREN 2591-D8-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D8 - Mating and Unmating Forces Issue P 1《航空航天系列.光电连接元件 试验方法 D8部分 啮合和非啮合力》.pdf
  • AECMA PREN 2591-D9-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D9 - Contact Retention in Insert Issue P 1《航空航天系列.光电连接的元件 试验方法 D9部分 触点插入保持》.pdf AECMA PREN 2591-D9-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D9 - Contact Retention in Insert Issue P 1《航空航天系列.光电连接的元件 试验方法 D9部分 触点插入保持》.pdf
  • AECMA PREN 2591-E1-1993 Aerospace Series Elements of Electrical and Optical Conncetion Test Methods Part E1 - Soft Soldering《航空航天系列.光电连接元件 试验方法 E1部分 软钎焊》.pdf AECMA PREN 2591-E1-1993 Aerospace Series Elements of Electrical and Optical Conncetion Test Methods Part E1 - Soft Soldering《航空航天系列.光电连接元件 试验方法 E1部分 软钎焊》.pdf
  • AECMA PREN 2591-E12-1993 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part E12 - Recommendation to Check Effectiveness of Non Removable Fixing of Her.pdf AECMA PREN 2591-E12-1993 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part E12 - Recommendation to Check Effectiveness of Non Removable Fixing of Her.pdf
  • AECMA PREN 2591-E2-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part E2 - Restricted Entry Issue P 1《航空航天系列.光电连接元件 试验方法 E2部分 禁止进入》.pdf AECMA PREN 2591-E2-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part E2 - Restricted Entry Issue P 1《航空航天系列.光电连接元件 试验方法 E2部分 禁止进入》.pdf
  • 相关搜索

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

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