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
Scrat [10]
3 years ago
6

using C++ to sort user input. for example, user enter 25numbers and sort them from small to big or big to small, cout thesamlles

t, the middle one on the sort list ( in 25 number would bethe 13th number) and the biggest?

Computers and Technology
1 answer:
Umnica [9.8K]3 years ago
4 0

Answer:

C++ code:

#include<iostream>

using namespace std;

void sort(int al[30], int l)

{

//we use insertion sort to sort the array.

int p,q,k;

for(q=1;q<l;q++)   //starting from the 2nd item of the array.

{

 k= al[q];   //taking qth item as key value.

 p=q-1;

 while(p>=0 && al[p]>k)

 {

  al[p+1]=al[p]; //all items those are greaer than al[q] are shifted //to right.

  p=p-1;

 }

 al[p+1]=k;

}

}

int main()

{

int p,l, arrl[30];

cout<<"Enter the number of items in your array: ";

cin>>l;

cout<<endl;

 

cout<<"Enter your "<<l<<" items"<<endl;

for(p=0;p<l;p++)

{

 cin>>arrl[p];

}

 

sort(arrl, l);  //call function sort() to sort the array.

 

cout<<"The array after sorting: ";

for(p=0;p<l;p++)

{

 cout<<arrl[p]<<" ";

}

cout<<endl;

 

cout<<"The smallest item is: ";

cout<<arrl[0]<<endl;

 

cout<<"The middle item is: ";

cout<<arrl[l/2]<<endl;

 

cout<<"The biggest item is: ";

cout<<arrl[l-1]<<endl;

}

Output is given as image.

You might be interested in
To paste text with the same formatting as the document in which it is entered, select _____ from the Paste menu. Keep Source For
SashulF [63]
Copy by command c and paste by command v
5 0
4 years ago
Read 2 more answers
What are the benefits of using disk cleanup as part of regular maintenance on a computer​
Morgarella [4.7K]

Your computer will absolutely benefit. Disk Cleanup is a Windows tool that lets you clean junk files and temporary files that are no longer needed, thus increasing space and performance.

4 0
3 years ago
Imagine you're developing a Pokemon game, and you need to implement the battle party mechanic. Recall that the player's party ca
valina [46]

Answer:

Complete code is given below and output is also attached.

Explanation:

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import java.util.Set;

public class Test {

  public static void main(String[] args) {

      String [] names = {"Pikachu", "Venuasur", "Charizard", "Blastoise", "Lapras", "Sonarlax"};

      int[] levels = {88, 84, 84, 84, 80, 82};

     

      ArrayList<HashMap<String, Integer>> party = createParty(names, levels);

     

      //looping through the list

      for(HashMap<String, Integer> i: party) {

         

          Set set = i.entrySet();

          Iterator itr = set.iterator();

          //showing output

          while(itr.hasNext()) {

              Map.Entry mentry = (Map.Entry)itr.next();

              System.out.println(mentry.getKey()+" "+mentry.getValue());

          }

      }

  }

  private static ArrayList<HashMap<String, Integer>> createParty(String[] names, int[] levels) {

      ArrayList<HashMap<String, Integer>> party = new ArrayList<>();

     

      for(int i=0; i<names.length; i++) {

          //creating new hashmap

          HashMap<String, Integer> pokemon = new HashMap<>();

          pokemon.put(names[i], levels[i]);//adding pokemon

          party.add(pokemon);//adding it to the list

      }

     

      return party;

  }

}

4 0
4 years ago
Look at the graph. What is the meaning of the point shown with a star
RUDIKE [14]
The answer is B. 1 Box= 1/2 Pounds
4 0
3 years ago
Which question would you ask when proposing a private cloud?
Ludmilka [50]
I think the answer would be C :)
5 0
3 years ago
Read 2 more answers
Other questions:
  • In a cellular network, where does each wireless base station connect to?
    9·1 answer
  • Instructions:Select the correct answer.
    15·1 answer
  • What function will delete an element from the end of a deque. On Edge
    13·1 answer
  • Which of the following is true for an API?
    6·1 answer
  • Importancia de la química en la vida cotidiana​
    15·1 answer
  • Jason is working on a Microsoft Excel worksheet and he wants to create a Print Preview shortcut. His teacher asks him to access
    9·1 answer
  • What is information communication technology?
    7·2 answers
  • A router periodically goes offline. Once it goes offline, you find that a simple reboot puts the router back online. After doing
    12·1 answer
  • The current annual interest rate is 5 percent, and you are taking out a 20-year loan with a monthly end-of-month payment. If you
    5·1 answer
  • Suppose you have 10 image files, each taking up 300 KB. About how many MB of space do they take up
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!