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
Which of the following would a high school graduate interested in the performing arts most likely do after graduation?
pashok25 [27]

Answer: College

Explanation: I got it right on my quiz

3 0
3 years ago
Carbon monoxide poisoning can result from breathing
Mamont248 [21]
The answer is the letter a
6 0
3 years ago
Rutherford concluded from his calculations that the volume of an atom is filled with protons, neutrons and electrons. is mostly
enyata [817]

Answer:

The answer is "is mostly empty space".

Explanation:

In the given question option numbers is defined, so the explanation to this question  as follows:

The volume of an element holds one mole at high temperatures. The nuclear mass is usually indicated by mole: cc/mol in the \ cm^3. It is also known as a quantity, in which the same molecule was the measured values based on atomic mass as well as the thickness of both, and certain alternatives were wrong which can be explained as follows:

  • atom doesn't fill the protons, neutrons, and electrons.
  • It can't revolve with outside atoms and electrons.

6 0
3 years ago
Amy uses digital devices to listen to music and to watch movies. Which one of these is Mbps a measure of?
posledela

Answer:

Storage Size

Explanation:

the answer to which is better 8 Mbps or 2 MBps? Is 2 MBps (which is 16 Mbps). Using a less common, but more clear notation: which is better 8 Mbit/s or 2 MBps? Answer: 2 MBps, since that is 16 Mbit/s. (Marketing people use this confusion to their advantage if you're not sure which is intended, ask.)

Source http://cs.sru.edu/~mullins/cpsc100book/module02_introduction/module02-05_introduction.html

(if you want to read the full artical.)

8 0
3 years ago
I WILL GIVE BRAINIEST ANSWER AND THANKS IF YOU ANDWER THIS QUESTION!!!!
sesenic [268]
Access: full electronic participation in society.
Commerce: electronic buying and selling of goods.
Communication: electronic exchange of information.
Literacy: process of teaching and learning about technology and the use of technology.
Etiquette: electronic standards of conduct or procedure.
Law: electronic responsibility for actions and deeds.
Rights & Responsibilities: those freedoms extended to everyone in a digital world.
Health & Wellness: physical and psychological well-being in a digital technology world.
Security (self-protection): electronic precautions to guarantee safety.

IMPORTANT
Etiquette. Students need to understand how their technology use affects others. ...
Literacy. Learning happens everywhere. ...
Rights and responsibilities. Build trust so that if something happens online, students are willing to share their problems or concerns about what has happened.
6 0
3 years ago
Other questions:
  • All of the following are incentives proprietary schools use to attract a student except
    7·2 answers
  • What is constructive criticism?
    5·1 answer
  • Engineers involved in product design and manufacturing use computer-aided design/computer-aided manufacturing (CAD/CAM) systems,
    13·1 answer
  • How to get the absolute value in coding begginners?
    13·2 answers
  • Which of these is most closely associated with system control? (1 point) (Points : 1.5) boundary
    10·1 answer
  • ASAP FAST PLSKara is currently creating a storyboard for her web site. Which step of the web design process is she in? Coding Pl
    9·2 answers
  • Implement a program called genes.py that does the following: a. Reads a DNA sequence t as command-line argument b. Reads strings
    9·1 answer
  • Computer application just help me with it all ?
    8·1 answer
  • What is the code i need to do
    12·1 answer
  • The method used to transfer information to far off place instantly is called​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!