如何matrix[i][j]在C++中找到给定矩阵()中的最大值,最小值和平均值.类型是unsigned long double.
这里没有什么聪明的做法(仅限伪代码,因为它闻起来像HW):
for each entry in the matrix:
add the entry to a running sum
compare the entry to a running min
if it's smaller, it's the new running min
compare the entry to a running max
if it's larger, it's the new running max
average is the sum divided by the number of entries
Run Code Online (Sandbox Code Playgroud)
您可以对该循环进行微优化以使其效率更高或更低,但是您无法通过算法进行更聪明的操作.无论如何,您都需要查看所有i*j条目.