Create a code using a function to sort 10 double values. Allow the user to input the values.
#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] << " ";
}
Comments
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.
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