Question #155576

Create a code using a function to sort 10 double values. Allow the user to input the values.


Expert's answer

#include <iostream>
#include <vector>
using namespace std;




void sort(vector<double>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = i + 1; j < a.size(); j++)
		{
			if (a[i] > a[j])
			{
				double k = a[i];
				a[i] = a[j];
				a[j] = k;
			}
		}
	}
}




int main()
{
	vector<double> a(10);
	for (int i = 0; i < 10; i++)
	{
		cin >> a[i];
	}
	sort(a);
	for (int i = 0; i < 10; i++)
		cout << a[i] << " ";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS