"Classroom Practice" output the maximum value in an array and test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.