Skip to content

Commit 5d761a2

Browse files
kthLargestNumber
1 parent 4a4ed70 commit 5d761a2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

kthLargestElement.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int a[50] , n , temp, k , i , j;
8+
cout<<"Enter the size of the array : ";
9+
cin>>n;
10+
cout<<"Enter the value of k : ";
11+
cin>>k;
12+
for(i=0;i<n;i++)
13+
{
14+
cout<<"Enter the "<<i+1<<" element : ";
15+
cin>>a[i];
16+
}
17+
18+
for(i=0;i<n;i++)
19+
{
20+
for(j=0;j<n-1;j++)
21+
{
22+
if(a[j] > a[j+1])
23+
{
24+
temp = a[j];
25+
a[j] = a[j+1];
26+
a[j+1] = temp;
27+
}
28+
}
29+
}
30+
cout<<k<<" th largest number is "<<a[n-k];
31+
return 0;
32+
}

0 commit comments

Comments
 (0)