-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathc3.cpp
More file actions
34 lines (31 loc) · 691 Bytes
/
c3.cpp
File metadata and controls
34 lines (31 loc) · 691 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
#include <iostream>
using namespace std;
int main(){
int n, num[50], largest, second;
cout<<"Enter number of elements: ";
cin>>n;
for(int i=0; i<n; i++){
cout<<"Enter Array Element"<<(i+1)<<": ";
cin>>num[i];
}
if(num[0]<num[1]){
largest = num[1];
second = num[0];
}
else{
largest = num[0];
second = num[1];
}
for (int i = 2; i< n ; i ++) {
if (num[i] > largest) {
second = largest;
largest = num[i];
}
else
if (num[i] > second && num[i] != largest) {
second = num[i];
}
}
cout<<"Second Largest Element in array is: "<<second;
return 0;
}