From 80b57c5d6687a4cc8a976eabde61cadb0f0b0e78 Mon Sep 17 00:00:00 2001 From: Praneetha29 <86006113+Praneetha29@users.noreply.github.com> Date: Tue, 5 Oct 2021 10:13:39 +0530 Subject: [PATCH] Finding Smallest element Solving issue #84 --- misc/Smallest element | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 misc/Smallest element diff --git a/misc/Smallest element b/misc/Smallest element new file mode 100644 index 0000000..9a3f592 --- /dev/null +++ b/misc/Smallest element @@ -0,0 +1,22 @@ + +#include +#include +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; +}