124.求二维数组周边元素之和
函数fun功能是:求出二维数组周边元素之和,作为函数值返回,二维数组中的值在主函数中赋予。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define M 4
#define N 5
int fun(int a[M][N])
{
int i, s = 0;
for (i = 0;i < N;i++)
s += a[0][i] + a[M - 1][i];
for (i = 1;i < M - 1;i++)
s += a[i][0] + a[i][N - 1];
return s;
}
int main()
{
int aa[M][N] = { {1,3,5,7,9},{2,9,9,9,4},{6,9,9,9,8},{1,3,5,7,0} };
int i, j, y;
printf("The original data is:
");
for (i = 0;i < M;i++)
{
for (j = 0;j < N;j++)
printf("%6d", aa[i][j]);
printf("
");
}
y = fun(aa);
printf("
The sun:%d
", y);
printf("
");
system("pause");
return 0;
}声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: 45.在字符串数组中查找给定的字符串
