forked from sat5297/hacktober-coding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxTwoNumbersInAnArray
More file actions
42 lines (39 loc) · 1.06 KB
/
maxTwoNumbersInAnArray
File metadata and controls
42 lines (39 loc) · 1.06 KB
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
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int a[10], i, largest = 0, second_largest = 0, pos1, pos2;
int n;
cout << "Enter Number of elements :";
cin>>n;
for (i = 0; i<n; ++i)
{
cout << "n Enter " << (i + 1) << "th Element :";
cin >> a[i];
}
//Finding Largest
for (i = 0; i<10; ++i)
{
if (a[i]>largest)
{
largest = a[i];
pos1 = i;
}
}
//finding second largset
for (i = 0; i<10; ++i)
{
if (a[i]>second_largest)
{
if (a[i] == largest)
continue;
second_largest = a[i];
pos2 = i;
}
}
cout << "nn Largest Number :" << largest << " at position " << (pos1 + 1);
cout << "nn Second Largest Number :"<< second_largest << " at position " << (pos2 + 1);
getch();
return;
}