Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C++ uses a function to output the maximum value and the second maximum value in an integer array.
C++ uses a function to output the maximum value and the second maximum value in an integer array.
# include & ltiostream & gt

const double max _ value(double arr[],double size);

Use namespace std

int main()

{

double arr[]={2,4, 1,7,3 };

Double size = 5.0;

double max = max_value(arr,size);

The maximum value of cout & lt& lt array is: "<& ltmax & lt& ltendl"

Returns 0;

}

const double max _ value(double arr[],double size)

{

double max = arr[0];

for(int I = 1; I< size; i++)

if(max & lt; arr[I])max = arr[I];

Return to max

}