#include<stdio.h>
int main()
{
int n,i,j,a[10],temp;
printf("Enter the no. of elements :\n");
scanf("%d",&n);
printf("enter the array elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("The original elements are \n");
for(i = 0 ; i < n ; i++)
printf("%d ",a[i]);
for(i= 0 ; i < n-1 ; i++)
{
for(j= 0 ; j< n-i-1; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
printf("\n The Sorted elements are \n");
for(i = 0 ; i < n ; i++)
printf("%d\t \n",a[i]);
return 0;
}
Output:
Enter the no. of elements :
5
enter the array elements
54321
The original elements are
54321
The Sorted elements are
1
2
3
4
5