(完整版)C语言考试题库及答案(20)

时间:2025-04-19

- 20 -

程序改错题(共15题)

1、在考生文件夹下,给定程序MODI.C 的功能是: 求一维数组a 中所有元素的平均值,结果保留两位小数。 例如,当一维数组a 中的元素为:10,4,2,7,3,12,5,34,5,9 程序的输出应为:The aver is: 9.10 。

#include <conio.h> #include <stdio.h> void main() {

int a[10]={10,4,2,7,3,12,5,34,5,9},i;

int aver,s;

s = 0;

for ( i=1; i<10; i++)

s += a[i]; aver = s / i;

printf("The aver is: %.2f\n", aver); }

2、在考生文件夹下,给定程序MODI.C 的功能是: 求二维数组a 中的最大值和最小值。 例如,当二维数组a 中的元素为: 4 4 34 37 3 12 5 6 5

程序的输出应为:The max is: 37 The min is: 3 。

#include <conio.h> #include <stdio.h> void main() {

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++)

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("The max is: %d\n", max); printf("The min is: %d\n", min); }

3、在考生文件夹下,给定程序MODI.C 的功能是: 求一维数组a 中的最大元素及其下标。

例如,当一维数组a 中的元素为:1,4,2,7,3,12,5,34,5,9, 程序的输出应为:The max is: 34,pos is: 7 。

#include <conio.h> #include <stdio.h> void main() {

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("The max is: %d ,pos is: %d\n", max , pos); }

4、在考生文件夹下,给定程序MODI.C 的功能是: 求二维数组a 中的最小值。

例如,当二维数组a 中的元素为: 4 2 34 7 3 12 5 6 5

程序的输出应为:The min is: 2 。

#include <conio.h> #include <stdio.h> void main() {

int a[3][3]={4,2,34,7,3,12,5,6,5},i,j,min; min = a[0][0];

for ( i=1; i<3; i++)

for ( j=0; j<3; j++) if (min > a[i][j]) {

/************found************/ min == a[i][j];

}

printf("The min is: %d\n", min); }

(完整版)C语言考试题库及答案(20).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219