二级c语言改错填空题库,2016最新二级C语言考试题库及答案(程序改错专项练习 精华版).doc...

2016最新二级C语言考试题库及答案(程序改错专项练习 精华版)

- PAGE 1 -

程序改错题(共15题)

1、在考生文件夹下,给定程序MODI.C的功能是:

求一维数组a中所有元素的平均值,结果保留两位小数。

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

程序的输出应为:The aver is: 9.10 。

#include

#include

void main()

{

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

float aver,s; /************found************/

float aver,s;

int aver,s;

/************found************/

s=a[0]; s = 0;

s=a[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

#include

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=0;j<3;j++) /************found************/

for(j=0;j<3;j++)

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

{ if ( max < a[i][j] )

max = a[i][j];

/************found************/

if(min>a[i][j]) if (min < a[i][j])

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

#include

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

if(max

{

max = a[i];

/************found************/

pos=i;i = pos;

pos=i;

}

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

#include

void main()

{

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

min = a[0][0];

for(i=0;i<3;i++) /************found**********

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值