-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond_lar.cpp
More file actions
61 lines (30 loc) · 772 Bytes
/
Copy pathsecond_lar.cpp
File metadata and controls
61 lines (30 loc) · 772 Bytes
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
#include<iostream>
using namespace std;
int main ()
{
int A[10], n, i, j, x;
cout << "Enter size of array : ";
cin >> n;
cout << "Enter elements of array : ";
for (i = 0; i < n; i++)
cin >> A[i];
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (A[i] < A[j])
{
x = A[i];
A[i] = A[j];
A[j] = x;
}
}
}
cout << "Second largest number : " << A[1];
cout << "\nSecond smallest number : " << A[n - 2];
return 0;
}
// another approach of sorting array in descending order and then printing the second largest number
for (i = 0; i < n; i++) {
cout << arr[i] <<endl;
}