Question #47952

How to sort in ascending mode

Expert's answer

Solution.

//Connectinglibrary
#include<iostream>
usingnamespace std;

intmain()
{
inta[10], swap;
for (int i = 0; i < 10; ++i )
{
cout <<endl<< "Enter thenumber: ";
cin>> a;
}

for (int i = 0; i < 10; ++i )
{
for( int j = i; j < 10; ++j )
{
if(a[j] < a[i] ) // ascending
{
swap= a[i];
a[i]= a[j];
a[j]= swap;
}
}
}

cout <<endl<< "Result:";
for ( int i = 0; i < 10; ++i )
{
cout << a[i] << " ";
}

cin.get();
//system(“pause”);
return 0;
}[i]


LATEST TUTORIALS
APPROVED BY CLIENTS