为方便广大考生更好的复习2013年计算机二级C语言考试,查找考试辅导习题,考试站网网校特提供了C语言上机预测题(填空题、改错题、编程题),更多模拟无纸化考试“计算机二级C语言模拟题”,供考生学习。
填空题
函数fun的功能是:将形参a所指数组中的前半部分元素中的值和后半部分元素中的值兑换。形参n中存在数组的个数,若n为奇数,则中间的元素不动。
例如;若a所指数组中的数据的依次为:1、2、3、4、5、6、7、8、9,则调换后为6、7、8、9、5、1、2、3、4。
注意:部分源程序给出如下
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。
试题程序:#include <stdio.h>
#define N 9
void fun(int a[], int n)
{
int i, t, p;
p = (n%2 == 0) ? n/2 : n/2 + ___1___;
for (i=0; i<n/2; i++)
{
t = a[i];
a[i] = a[p+___2___];
___3___ = t;
}
}
main()
{
int b[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9}, i;
printf("\nThe original data :\n");
for (i=0; i<N; i++)
printf("%4d ", b[i]);
printf("\n");
fun(b, N);
printf("\nThe data after moving :\n");
for (i=0; i<N; i++)
printf("%4d ", b[i]);
printf("\n");
}
第1处填空:1
第2处填空:i
第3处填空:a[p+i]或*(a+p+i)