一、程序改错题(找出程序的错误,改正后在电脑上运行)
1、在考生文件夹下,给定程序MODI.C的功能是: 求一维数组a中所有元素的平均值,结果保留两位小数。 例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 程序的输出应为:The aver is: 9.10 。
#include
int a[10]={10,4,2,7,3,12,5,34,5,9},i; /************found************/ intaver,s;
/************found************/ s = 0;
for ( i=1; i<10; i++) s += a[i]; aver = s / i;
printf(\}
2、在考生文件夹下,给定程序MODI.C的功能是: 求二维数组a中的最大值和最小值。 例如,当二维数组a中的元素为: 4 4 34 37 3 12 5 6 5
程序的输出应为:The max is: 37 The min is: 3 。
#include
int a[3][3]={4,4,34,37,3,12,5,6,5},i,j,max,min; max = min = a[0][0]; for ( i=0; i<3; i++)
/************found************/ for ( j=1; j<3; j++) { if ( max < a[i][j] ) max = a[i][j];
/************found************/ if (min < a[i][j]) min = a[i][j]; }
printf(\printf(\ }
3、在考生文件夹下,给定程序MODI.C的功能是: 求一维数组a中的最大元素及其下标。 例如,当一维数组a中的元素为:1,4,2,7,3,12,5,34,5,9, 程序的输出应为:The max is: 34,pos is: 7 。
#include
int a[10]={1,4,2,7,3,12,5,34,5,9},i,max,pos; max = a[0]; pos = 0;
for ( i=1; i<10; i++)
/************found************/ if (max > a[i]) { max = a[i];
/************found************/ i = pos; }
printf(\} }
二、程序填空题(补充完整程序的空白处,并在电脑上运行) 3、在考生文件夹下,给定程序FILL.C的功能是:
统计整数n的各个位上出现数字1、2、3的次数,并通过外部(全局)变量c1、c2、c3返回主函数。 例如,当n=123114350时,结果应该为:c1=3 c2=1 c3=2。
#include
c1 = c2 = c3 = 0; while (n) {
/************found************/ switch(___1___) {
case 1: c1++; break;
/************found************/ case 2: c2++;___2___; case 3: c3++;
}
n /= 10; } }
main() {
int n=123114350; fun(n);
printf(\
4、在考生文件夹下,给定程序FILL.C的功能是:
程序的功能是计算y = 0! + 1! + 2! + 3! + 4! + …… + n! 如输入n的值为5的话,则输出y值为154 #include
s=1; for (i=1; i<=n; i++)
/************found************/ s=___1___; return s; } main() { int s; int k,n;
scanf(\s=0; for (k=0; k<=n; k++)
/************found************/ s=___2___; printf(\ }
8、在考生文件夹下,给定程序FILL.C的功能是:
打印出1至1000中满足其个位数字的立方等于其本身的所有整数。本题的结果为:1 64 125 216 729。 #include
int i,g;
for(i=1;i<1000;i++) {
/************found************/ g=i___1___10; /************found************/ if(___2___) printf(\}
printf(\}
三、程序设计题(编写空白处程序段并运行)
1、在考生文件夹下,要求程序PROG.C的功能是:
将字符串中所有的大写字母转换为小写,其它字符不变(不使用转换函数)。 例如,当字符串为\输出:\
#include
/***********begin***********/
/************end************/ }
void main() {
char str1[80];
printf(\gets(str1); fun(str1);
printf(\ }
2、在考生文件夹下,要求程序PROG.C的功能是:
求[1,1000]之间既不能被7整除也不能被5整除的整数之和,将结果存入变量s中。
#include \ #include \ #include \void main() { int s; inti;
/***********begin***********/
/************end************/ printf(\ }
3、在考生文件夹下,要求程序PROG.C的功能是: 统计字符串中元音字母’a’、’e’、’i’、’o’、’u’的个数并输出。 例如,当字符串为\输出:Result is: 4 #include
/***********begin***********/
/************end************/ }
void main() { char str1[80]; int n;
printf(\gets(str1);
n=fun(str1);
printf(\ }
5、在考生文件夹下,给定程序PROG.C的功能是: 求N*N矩阵的第2行(以下标为行数)元素的和并输出。 例如,当矩阵为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
则第2行元素是:9,10,11,12。第2行元素之和为:42 #include
/***********begin***********/
/************end************/ }
void main() {
int a[N][N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; inti,j,sum;
printf(\for(i=0;i for(j=0;j printf(\ printf(\ } sum=fun(a); printf(\:%d\\n\ }