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: