'C++ sorting an array in ascending order Printing

Im trying to sort an array in ascending order and print it out and Im having trouble of where to put my cout in my code.

for (int k=0; k<ARRAY_SIZE; k++) {
    for (int l=1; l<ARRAY_SIZE-1; l++) {
        if(numbers[l] > numbers[k]) {
            temp = numbers[k];
            numbers[k] = numbers[l];
            numbers[l] = temp;
        }
        cout<<numbers[k];
    }    
}


Solution 1:[1]

If you want to see the result of sorting you have to print the array in new for loop

Solution 2:[2]

Remove the actual cout and put it after the sorting loop, in a new loop

for(int k = 0 ; k < ARRAY_SIZE; ++k)
    cout << numbers[k] << " ";

Solution 3:[3]

This is a program that finds the length of a number n and converts it to an array arr and sorts that array in ascending order.(possible aptitude question)

#include <iostream>
using namespace std;
int main()
{
    int n,i=0,j,num,temp,len=0,arr[10]={0};
    cin>>n;
    num=n;
while(n!=0)
    {
        len++;
        n/=10;
    }
    cout<<len<<endl;
    for ( i = len; i >= 0; i--)
        {
            arr[i] = num%10;
            num/=10;
    }
for(i=1;i<=len;i++)
    for(j=0;j<=len-i;j++)
{
    if(arr[j]>arr[j+1])
    {
        temp=arr[j];
        arr[j]=arr[j+1];
        arr[j+1]=temp;
    }
}
for(i=1;i<=len;i++)
{
    cout<<arr[i]<<endl;
}
return 0;
}

Solution 4:[4]

try this :

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
//array declaration
int arr[] = {1,2,5,8,4,3};
int n,i,j;
n = sizeof(arr) / sizeof(arr[0]);
int temp;

//print input elements
cout<<"Unsorted Array elements:"<<endl;
for(i=0;i<n;i++)
if(arr[i] == arr[n - 1]){
    cout<<arr[i]<<"";
}else{
    cout<<arr[i]<<",";
}
cout<<endl;

//sorting - ASCENDING ORDER
for(i=0;i<n;i++)
{       
    for(j=i+1;j<n;j++)
    {
        if(arr[i]>arr[j])
        {
            temp  =arr[i];
            arr[i]=arr[j];
            arr[j]=temp;
            
        }
        
    }
    
}
//print sorted array elements
cout<<"Sorted (Ascending Order) Array elements:"<<endl;

for(i=0;i<n;i++)
if(arr[i] == arr[n - 1]){
    cout<<arr[i]<<"";
}else{
    cout<<arr[i]<<",";
}
    
cout<<endl; 


return 0;



}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Angen
Solution 2
Solution 3 apex predator
Solution 4