Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The first integer indicates how many numbers are in the list. Assume that the list will always contain less than 20 integers.

Ex:

If the input is: 5 10 4 39 12 2

the output is: 2 4 10 12 39

For coding simplicity, follow every output value by a space, including the last one. Your program must define and call the following function. When the SortArray function is complete, the vector passed in as the parameter should be sorted. void SortVector(vector& myVec)

Respuesta :

The program is an illustration of loops.

Loops are used to perform repetitive and iterative operations.

The program in C++ where comments are used to explain each line s as follows:

#include <iostream>

#include <vector>

using namespace std;

//This defines the vector_sort function

void vector_sort(vector<int> &vec) {

   //This declares temp as integer

   int temp;

   //This iterates through the vector elements

   for (int i = 0; i < vec.size(); ++i) {

       //This iterates through every other vector elements

       for (int j = 0; j < vec.size() - 1; ++j) {

           //The following if condition sorts the vector elements

           if (vec[j] > vec[j + 1]) {

               temp = vec[j];

               vec[j] = vec[j + 1];

               vec[j + 1] = temp;

           }

       }

   }

}

//The main method begins here

int main() {

   //This declares the vector size and the inputs as integers

   int size, n;

   //This declares the vector as integer

   vector<int> v;

   //This gets input for the vector size

   cin >> size;

   //The following iteration gets input for the vector

   for (int i = 0; i < size; ++i) {

       cin >> n;

       v.push_back(n);

   }

   //This calls the vector_sort method

   vector_sort(v);

   //The following iteration prints the sorted vector

   for (int i = 0; i < size; ++i) {

       cout << v[i] << " ";

   }

   return 0;

}

Read more about similar programs at:

https://brainly.com/question/14805260