#include<stdio.h>
int main(){
int n,i,j,temp,a[20];
printf("Enter The number of elements elements: ");
scanf("%d",&n);
printf("Enter %d elements: ",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("After sorting is: ");
for(i=0;i<n;i++)
printf(" %d",a[i]);
return 0;
}
Output:
Enter the number of elements: 4
Enter 4 elements: 9 6 1 5
After sorting is: 1 5 6 9
No comments:
Post a Comment