Answer to Question #155576 in C++ for LYKA

Question #155576

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


1
Expert's answer
2021-01-14T09:01:35-0500
#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!

Comments

Assignment Expert
18.01.21, 09:25

Dear Haider Ali rana, Questions in this section are answered for free. We can't fulfill them all and there is no guarantee of answering certain question but we are doing our best. And if answer is published it means it was attentively checked by experts. You can try it yourself by publishing your question. Although if you have serious assignment that requires large amount of work and hence cannot be done for free you can submit it as assignment and our experts will surely assist you.

Haider Ali rana
17.01.21, 08:57

As I don't have a knowledge of class and structure so can you please help me to how to do this code by only using functions.

Leave a comment

LATEST TUTORIALS
New on Blog