Qt 数组最大值获取:使用 qMax() 函数
你可以使用 'qMax()' 函数来获取一个 'double' 数组的最大值。以下是一个示例代码:
#include <QtDebug>
int main()
{
double arr[] = {1.2, 3.4, 2.1, 5.6, 4.9};
int size = sizeof(arr) / sizeof(arr[0]);
double maxVal = arr[0];
for(int i = 1; i < size; i++)
{
maxVal = qMax(maxVal, arr[i]);
}
qDebug() << "最大值为:" << maxVal;
return 0;
}
输出结果为: '最大值为: 5.6'
原文地址: https://www.cveoy.top/t/topic/qawx 著作权归作者所有。请勿转载和采集!