#include<stdio.h>
int main()
{
int n,temp,i,j,x[20];
printf("Enter total numbers of elements: ");
scanf("%d",&n);
printf("Enter %d elements: ",s);
for(i=0;i<n;i++)
scanf("%d",&x[i]);
for(i=n-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(x[j]>x[j+1])
{
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
}
}
printf("After sorting: ");
for(i=0;i<n;i++)
printf(" %d",x[i]);
return 0;
}
Output:
Enter total numbers of elements: 4
Enter 4 elements: 8 9 3 10
After sorting: 3 8 9 10
No comments:
Post a Comment