Write a function that reads an double array and its size, then return the maximum value. The main program has been given to you. The result should be 5.9
时间: 2023-03-15 17:33:31 浏览: 131
A simple program that shows how a two-dimensional array work
#include <stdio.h>
int max(double array[], int size){
double maxValue = array[0];
for(int i = 1; i < size; ++i){
if(array[i] > maxValue){
maxValue = array[i];
}
}
return maxValue;
}int main() {
double array[] = {2.6, 1.5, 5.9, 3.7};
int size = sizeof(array) / sizeof(double);
printf("Max Value: %f", max(array, size));
return 0;
}结果是5.9。
阅读全文