How to print numbers in an array in ascending and descending order???

closed account (3hMz8vqX)
Hi All,

Can you guys give a very simple example of an ascending order program ???

I got this code from the internet . . .

 12345678910111213141516171819202122232425262728293031323334353637 #include using namespace std; #define maxsize 100 int main() { int temp, i, j, n, list[maxsize]; cout<<"\n--You are prompted to enter your list size.--"; cout<<"\n--Then, for your list size, you are prompted to enter--"; cout<<"\n--the element of your list.--"; cout<<"\n--Finally your list will be sorted ascending!!!--\n"; // get the list size... cout<<"\nEnter your list size: "; cin>>n; // prompting the data from user and store it in the list... for(i=0; i"; cin>>list[i]; } // do the sorting... for(i=0; i list[j]) { // these three lines swap the elements list[i] and list[j]. temp = list[i]; list[i] = list[j]; list[j] = temp; } cout<<"\nSorted list, ascending: "; for(i=0; i

What is this line of code:

for(j=i+1; j<n; j++)
if(list[i] > list[j])
{
// these three lines swap the elements list[i] and list[j].
temp = list[i];
list[i] = list[j];
list[j] = temp;
}

I dont understand the logic . . .
Can anyone explain this part to me ???

Similarly how do you make a descending order of this ???