Exercise>>Code realizes the sum of the numbers on the intersection line of the 5*5 array (the number in the middle only needs to be calculated once)

5*5 array

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



Compute the sum of the numbers on the intersection



Code:

#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;
}


Guess you like

Origin blog.csdn.net/2301_77509762/article/details/130812578