Basic Practice Sequence Features


Problem Description
Given n numbers, find the maximum, minimum, and sum of these n numbers.


The first line of the input format
is an integer n, which represents the number of numbers.


The second line has n numbers, which are given n numbers, and the absolute value of each number is less than 10000.


The output format
outputs three lines, one integer per line. The first row represents the maximum of these numbers, the second row represents the minimum of these numbers, and the third row represents the sum of these numbers.
Sample input
5
1 3 -2 4 5
Sample output
5
-2
11
Data size and convention
1 <= n <= 10000.

#include<cstdio>
#include<iostream>
#include<cmath>

using namespace std;

int main(){
		int n,max,min,sum;
		int a[10001];
		cin>>n;
		for(int i=0;i<n;i++)
			cin>>a[i];
		max=min=sum=a[0];
		for(int i=1;i<n;i++){
			if(a[i]>max)
				max=a[i];
			if(a[i]<min)
				min = a [i];
			sum+=a[i];
		}
		cout<<max<<endl;
		cout<<min<<endl;
		cout<<sum<<endl;	
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326214027&siteId=291194637