问题 问答题

请编写函数fun,其功能是:找出2xM整型二维数组中最大元素的值,并将此值返回调用函数。
注意:部分源程序给出如下。
请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#define M 4
#include <stdio.h>
int fun (int a[][M])


void main ()

int arr[2][M]=5, 8, 3, 45, 76,
4, 12, 82;
printf("max=% d\n", fun(arr));

答案

参考答案:

int fun (int a[][M])

{

int i,j,max=a[0][0];

for(i=0;i<B;i++)

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

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

max=a[i][j];

return max;

}

解析:

题且要求数组的最大值,需要运用循环语句,因为数组是二维数值,所以应使用二层加for循环嵌套。使用for循环语句时需要注意循环变量的取值范围。

[解题思路] 此类求最大值或最小值的问题,我们可以采用逐个比较的方式,要求对数组中所有元素遍历一遍,并且从中找出数组最大值或最小值。首先定义变量max存放数组中的第一个元素的值,然后利用for循环逐个找出数组中的元素,并与max比较,如果元素值大于max,则将该值赋于max,循环结后max的值即为数组最大值,最后将该值返回。

[解题宝典] 该类题目考查较多,要掌握逐行比较的方法。对于m*n二维数组,如采用逐行查找方法,代码实现为:

for(i=0; i<m; i++)

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

……

阅读理解

阅读理解。

     When I was 13 years old, a boy gave me an important gift. It was a smile.

     It was the early autumn of my first year at a junior high school, and my old school was far away. As a

result, no one knew who I was. I was very lonely, and afraid to make friends with anyone.

     Every time I heard the other students talking and laughing, I felt my heart break. I couldn't talk to

anyone about my problem, and I didn't want my parents to worry about me.

     Then one day, my classmates talked happily with their friends, but I sat at my desk unhappily as usual.

At that moment, a boy entered the classroom. I didn't know who he was. He passed me and then turned

back. He looked at me and, without a word, smiled.

     Suddenly, I felt the touch of something bright and friendly. It made me feel happy, lively and warm.

     That smile changed my life. I started to talk with the other students and made friends. Day by day, I

became closer to everyone in my class. The boy with the lucky smile has become my best friend now.

     One day, I asked him why he smiled, but he couldn't remember smiling at me!

It doesn't matter because all the dark days have gone. Now I believe that the world is what you think it is.

If you think you are lonely, you might always be alone. So smile at the world and it will smile back.

1. Why was the smile an important gift?

A. The writer's old school was far away.

B. It made the writer feel happy, lively and warm.

C. The writer didn't know who the boy was.

D. The smile didn't mean anything to the writer.

2. Why do you think the boy smiled?

A. He was happy to see his friends.

B. He saw the writer was unhappy.

C. He really liked the writer.

D. He was a very friendly boy and smiled at everyone.

3. How did the smile change her life?

A. She began to make new friends.

B. She became best friends with the boy.

C. Her parents didn't worry about her any more.

D. She realized that it's important to smile at people.

4. Where does she now think her feeling of unhappiness came from?

A. From her old school.

B. From herself.

C. From other people in the world.

D. From the children at the new school.

填空题