练习>>代码实现5*5数组的交叉线上数字之和(中间的那个数只需要计算一次)

5*5数组

1     3     5     7    9

2     4     6     8   10

2     3     4     5    6

4     5     6     7    8

1     3     4     5    6



计算交叉线上数之和



代码实现:

扫描二维码关注公众号,回复: 15496432 查看本文章

#include <stdio.h>
int fun(int a[5][5])
{
	return a[0][0] + a[1][1] + a[2][2] + a[3][3] + a[4][4] + a[0][4] + a[1][3] + a[3][1] + a[4][0];
}

int main()
{
	int a[5][5] = { {1,3,5,7,9} ,{2,4,6,8,10}, {2,3,4,5,6}, {4,5,6,7,8}, {1,3,4,5,6} };
	int y = 0;
	y = fun(a);
	printf("s=%d\n",y);

	return 0;
}


猜你喜欢

转载自blog.csdn.net/2301_77509762/article/details/130812578
今日推荐