|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请编写函数fun,其功能是:找出2×M整型二维数组中最大元素的值,并将此值返回调用函数。
注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include <stdio.h>
#define M 4
int fun(int a[][M])
{
}
int main()
{
int arr[2][M] = {5, 8, 3, 45, 76, -4, 12, 82};
printf("max = %d\n", fun(arr));
return 0;
}
- #include <stdio.h>
- #define M 4
- int fun(int a[][M])
- {
- int i=0, *ptemp=(int *)a,temp=a[0][0];
- for (i=0;i<2*M;i++)
- {
- if(temp<*ptemp) temp=*ptemp;
- ptemp++;
- }
- return temp;
- }
- int main()
- {
- int arr[2][M] = {5, 8, 3, 45, 76, -4, 12, 82};
- printf("max = %d\n", fun(arr));
- return 0;
- }
复制代码
|
|