"Waterloo Cup" basic exercise: sequence characteristics

Source: Internet
Author: User

Problem description

Give the number of N, find the maximum value, the minimum, and the number of N. Input format

The first behavior is an integer n that represents the number of numbers.

The second row has n number, for the given number of n, the absolute value of each number is less than 10000. Output format outputs three rows, one integer per line. The first line represents the maximum value in these numbers, the second row represents the minimum value in those numbers, and the third line represents the number of these numbers. Sample Input 5
1 3-2 4 5 Example output 5
-2
11 Data size and convention 1 <= N <= 10000.


Experience:

Find the maximum value, the minimum value, and the amount of all elements. Edge Input edge processing. If there is a clear range of data in the topic, assign the variable Max to-(Clear data range + any number not to be 0), the min assignment is + (clear data range + any number not to 0), if there is no clear data range, the variable max and Min are assigned the first number of the array.

Code:

#include <iostream>
using namespace std;
int num[10003];
int main ()
{
    int max=-10004;
    int min=10004;
    int sum=0;
    int n;
    cin>>n;
    for (int i=0;i<n;++i)
    {
        cin>>num[i];
        if (Max<num[i])
            max=num[i];
        if (Min>num[i])
            min=num[i];
        Sum+=num[i];
    }
    cout<<max<<endl;
    cout<<min<<endl;
    cout<<sum;
    return 0;
}

Run:


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.