-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2nd day
79 lines (72 loc) · 1.44 KB
/
2nd day
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//Problem 1 - Reverse the array 3
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, t, i, j, temp;
cin >> t;
while (t--)
{
cin >> n;
int *arr = new int[n];
for (i = 0; i < n; i++)
{
cin >> arr[i];
}
i = 0;
j = n - 1;
while (i < j)
{
temp = arr[i];
arr[i++] = arr[j];
arr[j--] = temp;
}
for (i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
cout << endl;
}
return 0;
}
Problem 2 - Maximum and Minimum element of the array
#include <stdio.h>
struct pair
{
long long int min;
long long int max;
};
struct pair getMinMax(long long int arr[], long long int n);
int main()
{
long long int t, n, a[100002], i;
struct pair minmax;
scanf("%lld", &t);
while (t--)
{
scanf("%lld", &n);
for (i = 0; i < n; i++)
scanf("%lld", &a[i]);
minmax = getMinMax(a, n);
printf("%lld %lld\n", minmax.min, minmax.max);
}
return 0;
}
struct pair getMinMax(long long int arr[], long long int n)
{
struct pair minmax;
minmax.min = arr[0];
minmax.max = arr[0];
for (int i = 1; i < n; i++)
{
if (arr[i] > minmax.max)
{
minmax.max = arr[i];
}
if (arr[i] < minmax.min)
{
minmax.min = arr[i];
}
}
return minmax;
}