ZZULIOJ1128 (C language implementation)

insert image description hereThe question requires the above
problem-solving ideas. The key point of our question is to access the elements of the first column of rows 0, 1, and 2 at one time, and then access the elements of the second column of rows 0, 1, and 2. We can first The elements are stored in an array, and then the column is accessed first. In the idea of ​​accessing the row, let’s not talk about the source code:
int main()
{ int m = 0;//row int n = 0;//column scanf_s(" %d %d", &m, &n); double arr[1001][11] = { 0 }; int i = 0; int j = 0; for (i = 0; i < m; i++) {







	for ( j = 0; j < n; j++)
	{
		scanf_s("%lf", &arr[i][j]);

	}

	
}
for ( i = 0; i < n; i++)//依次访问第0行第1、2、3个元素,
{
	double sum = 0;//每次sum置为0.
	for ( j = 0; j < m; j++)
	{
		sum += arr[j][i];
	}
	double ave = sum / m;//每次求出平均值输出
	

	printf("%.2f ", ave);

}

return 0;
}
There is a point that needs attention in this question: when defining an array, you need to define a double-type two-dimensional array, otherwise the test case will not pass!

Guess you like

Origin blog.csdn.net/Kirihara_Yukiho/article/details/123948553