Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 002_ARRAY/011_Largest_element_in_Array
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<iostream>
using namespace std;
void kLargest(int nums[], int n, int k)
{
sort(nums, nums+n, greater<int>());
cout << "\nLargest " << k << " Elements: ";
for (int i = 0; i < k; i++)
cout << nums[i] << " ";
}

int main()
{
int nums[] = {4, 5, 9, 12, 9, 22, 45, 7};
int n = sizeof(nums)/sizeof(nums[0]);
cout << "Original array: ";
for (int i=0; i < n; i++)
cout << nums[i] <<" ";
int k = 4;
kLargest(nums, n, k);
}