手机版

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

时间:2025-07-04   来源:未知    
字号:

- 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文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)