-
Notifications
You must be signed in to change notification settings - Fork 1
/
Maximum_and_Minimum_of_Array_Elements.cpp
60 lines (50 loc) · 1.16 KB
/
Maximum_and_Minimum_of_Array_Elements.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Problem Statement:
-----------------
Given an array A[ ], find maximum and minimum elements from the array.
Input:
The first line of input contains an integer T, denoting the number of testcases. The description of T testcases follows. The first line of each testcase contains a single integer N denoting the size of array. The second line contains N space-separated integers A1, A2, ..., AN denoting the elements of the array.
Output:
For each testcase in a new line, print the maximum and minimum element in a single line with space in between.
Constraints:
1 ≤ T ≤ 30
1 ≤ N ≤ 100
0 ≤A[i]<100
Example:
Input:
2
4
5 4 2 1
1
8
Output:
5 1
8 8
*/
// Link --> https://practice.geeksforgeeks.org/problems/maximum-and-minimum-of-array-elements/0#
// Code:
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n];
for(int i=0 ; i<n ; i++)
cin>>a[i];
int min = a[0] , max = a[0];
for(int i=0 ; i<n ; i++)
{
if(a[i] > max)
max = a[i];
else if(a[i] < min)
min = a[i];
}
cout<<max<<" "<<min<<endl;
}
return 0;
}