Design ideas
When debugging, as much as possible to take into account all possible situations, enter these conditions, to see the results of the program running
Source
#include <iostream>
using namespace Std;
int largest (int list[], int length);
int main ()
{
int list[100];
int lenght;
int i;
cout << "Please enter the length of the one-dimensional array:";
Cin >> Lenght;
if (lenght = = 0)
{
Cerr << "Array length cannot be zero!! "<< Endl;
return 0;
}
cout << "Please enter" << lenght << "integer:";
for (i = 0; i < lenght; i++)
{
CIN >> List[i];
}
cout << "The maximum value of this array is:" << largest (list, lenght) << Endl;
return 0;
}
int largest (int list[], int length)
{
int i, max=list[0];
for (i = 1; i < length; i++)
{
if (List[i] > Max)
{
max = List[i];
}
}
return Max;
}
Test
Issues found
Array length input is the character is the program error, also cannot be a floating-point number, negative, such as non-0 natural numbers;
The numbers in the array are calculated by the integer portion of the input floating-point number when the float is entered;
When Max's initial value is set to List "0", the value of I can start at 1;
Summarize
To treat each procedure with a special and rigorous attitude;
Should keep in mind that the computer is dead, and people are alive, the program is possible, can not let go of any detail!
Max Value-Unit test