Skip to content

Commit

Permalink
Finding Smallest element
Browse files Browse the repository at this point in the history
Solving issue tornado-12#84
  • Loading branch information
Praneetha29 authored Oct 5, 2021
1 parent fe9761b commit 80b57c5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions misc/Smallest element
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#include<iostream>
#include<algorithm>
using namespace std;


int kthSmallest(int arr[], int n, int k)
{

sort(arr, arr+n);


return arr[k-1];
}

int main()
{
int arr[] = {12, 3, 5, 7, 19};
int n = sizeof(arr)/sizeof(arr[0]), k = 2;
cout << "K'th smallest element is " << kthSmallest(arr, n, k);
return 0;
}

0 comments on commit 80b57c5

Please sign in to comment.