You are on page 1of 1

//Create a program that will insert and display the elements of an array, in

ascending order(Least to greatest)//


#include<iostream>
using namespace std;

int main()
{
int arr[100];
int size, k, l, temp;

// What will be the size of array


cout<<"Enter size of array: ";
cin>>size;

//Different values of the array


cout<<"Enter values in array: ";
for(k=0; k<size; k++)
{
cin>>arr[k];
}
//Display the values in ascending order
for(k=0; k<size; k++)
{
for(l=k+1; l<size; l++)
{
//If there is a smaller element found on right of the array then swap
it.
if(arr[l] < arr[k])
{
temp = arr[k];
arr[k] = arr[l];
arr[l] = temp;
}
}
}
//Output the order from least to greatest
cout<<"Elements of array from least to greatest order:"<<endl;
for(k=0; k<size; k++)
{
cout<<arr[k]<<endl;
}

return 0;
}

You might also like