Design ideas
The function is used to encapsulate the code of the maximum value of the array, and the function is called in the main function.
SOURCE program code
#include <iostream>
using namespace Std;
int largest (int list[],int length)
{
int i;
int max=list[0];
for (i=0;i<length;i++)
{
if (List[i]>max)
{
Max=list[i];
}
}
return Max;
}
void Main ()
{
int I,max;
int x[5];
cout<< "Please enter an array:" <<endl;
for (i=0;i<5;i++)
{
cin>>x[i];
}
cout<< "The maximum value of the array is:" <<endl;
Max=largest (x,5);
cout<<max;
}
Test
Test
Issues found
1. When entering floating-point data, the integer portion of floating-point type is used by default to participate in comparison size
2, input character data, display garbled, program crashes.
Programming summary
Program testing is very important, is an indispensable process, is conducive to the discovery programmer programming without consideration of the vulnerability, is the guarantee of program robustness!
"Classroom Practice" output the maximum value in an array and test