#include<stdio.h>
int main()
{
int a[100],i,j,n;
int temp,flag=0;
printf("Enter size of arrray:");
scanf("%d",&n);
printf("Enter %d elements of array:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
flag=0;
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;
flag=1;
}
}
if(flag==0)
{
break;
}
}
printf("\n After sorting elements of array in Ascending order are:\n");
for(i=0;i<n;i++)
{
printf("\n%d",a[i]);
}
return 0;
}
***OUTPUT***
0 Comments