全国计算机等级考试二级C语言机试真题2008年4月_真题-无答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
全国计算机等级考试二级C语言机试真题2008年4月
(总分100,考试时间90分钟)
1、程序填空题
1. 下列给定的程序中,函数fun()的功能是:求出以下分数序列的前n项和。
2/1,3/2,5/3,8/5,13/8,21/13,…
其值通过函数值返回main()函数。
例如,若输入n=5,则应输出8.391667。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
#include<stdio.h>
#include<conio.h>
double fun(int n)
int a=2, b=1, c, k;
double[ (1) ];
for(k=1; k<=n; k++)
s=s+1.0 *a/b;
c=a; a+=[ (2) ]; b=c;
return(d);
main()
int n=5;
printf("\nThe value of function is: %1f\n", [ (3) ]);
2、程序修改
1. 下列给定程序中,函数fun()的功能是:用选择法对数组中的n个元素按从小到大的顺序进行排序。
请改正程序中的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<stdio.h>
#define N 20
void fun(int a[], int n)
int i, j, t, p;
for(j=0; j<n-1; j++)
/***********found***********/
p=j
for(i=j; i<n; i++)
if(a[i]<a[p])
/***********found***********/
p=j;
t=a[P];
a[p]=a[j];
a[j]=t;
msin()
int a [N]=(9, 6, 8, 3, -1), i, m=5;
printf("排序前的数据:”);
for(i=0; i<m; i++)
printf("%d", a[i]);
printf("\n");
fun(a, m);
printf("排序后的数据:");
for(i=0; i<m; i++)
printf("%d", a[i]);
printf("\n");
3、程序设计
1. 请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要
求把下标从p~n-1(p<n-1)的数组元素平移到数组的前面。
例如,一维数组中的原始内容为1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, P的值为6。
移动后,一维数组的内容应为7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
[试题源程序]
#inciude <stdio.h>
#define N 80
void fun(int *w, int p, int n)
main()
int a[N]=(i, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
int i, P, n=15;
printf("The original data:\n");
for(i=0; i<n; i++)
printf("%3d", a[i]);
printf("\n\nEnter p: ");
scanf("%d", &p);
fun(a, P, n);
printf("\nThe data after moving:\n");
for(i=0; i<n; i++)
printf("%3d", a[i]);
printf("\n\n");。