1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Amiraneli [1.4K]
3 years ago
7

Write a C++ program to find K largest elements in a given array of integers. For eeample, if K is 3, then your program should ou

put the largest 3 numbers in teh array. Your program is not supposed to use any additional array.
Computers and Technology
1 answer:
Anon25 [30]3 years ago
4 0

Answer:

// C++ program to find k largest elements in the array

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variable

int n,k;

cout<<"Enter the number of elements of array:";

// read the value of n

cin>>n;

// declare the array of size n

int arr[n];

cout<<"Enter the elements of array:";

// read the elements of array

for(int a=0;a<n;a++)

{

   cin>>arr[a];

}

cout<<"Enter the value of K:";

cin>>k;

// call the function to perform selection Sort

sort(arr, arr+n);

cout << k<<" largest elements of the array are: ";

// print k largest elements of the array

for (int i=n-1; i>n-k-1; i--)

cout << arr[i] << " ";

return 0;

}

Explanation:

Read the number of elements in the array.Then create an array of size "n" and read  n elements of the array.Sort the array in ascending array.Then Read the value of  k from user.Find the k Elements from the end of the array.This will be the k  largest elements of the array.

Output:

Enter the number of elements of array:8                                                                                    

Enter the elements of array:34 8 75 99 12 7 5 55                                                                          

Enter the value of K:3                                                                                                    

3 largest elements of the array are: 99 75 55

You might be interested in
What does the<br> command do
I am Lyosha [343]
Please specify your question.
6 0
3 years ago
Kyle, a receptionist for a building supply company, recently won an award for saving his company money on their phone system. Af
Akimi4 [234]
The answer is most likely VoIP which means Voice over Internet Protocol. This is for example skype
8 0
3 years ago
Read 2 more answers
given the numerical value 1010101.11, which of the following number systems is most likely represented.
nasty-shy [4]

Answer:

u have to give me more points

Explanation:

sorry

7 0
3 years ago
What type of firewall inspects network traffic at a higher level in the osi model than a traditional stateful packet inspection
rjkz [21]
Anti malware I believe good luck
4 0
3 years ago
Why does Brainly keep on giving me ads. All I want to do is get answers not be smothered by a bunch of ads. And then when you go
weqwewe [10]

Answer:

Hello Fellow Brainliest!

This problem occurred for me sevreal times for me.

Here are some things that I tried that resolved the problem.

1. Switch Browsers

2. Make a new account.

3. Turn off your device, then turn it back on.

_____________________________________

**Other Options that might work**

1. Virus Scan

Sometimes a buggy device might lead to these problem.

2. Clear Your Catche

Sometimes You have extra files that lead to lots of ads.

________________________________________________

(Hope this helps luv)

-TheAnimeCatUwU

5 0
3 years ago
Other questions:
  • What is the purpose of look up tables in spreadsheet software apex
    13·1 answer
  • Describe the difference between public and private IPv4 addresses. If a network is using private IP addresses, how can the compu
    13·1 answer
  • Technology offers a variety of rich opportunities available to teachers and students. According to Inan and Lowther (2010), ther
    6·1 answer
  • What does the line of red semicircles mean on a weather map
    11·1 answer
  • Arrays enable the representation of a number of similar items (in terms of their datatypes). They represent these items in an or
    9·1 answer
  • For LG, on the app Messages, will the delete button on the upper right corner cancel a sending message?
    12·1 answer
  • Your computer has been showing signs of a malware infection, and today it started up in Safe Mode. Because your computer is not
    6·1 answer
  • Need the answer for this code hs will give brainly
    7·1 answer
  • 8.10 Code Practice Question 1
    12·1 answer
  • Compare and contrast the various write strategy used in cache technologies<br>​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!