#include<stdio.h>
#define MAX 20
int main()
{
int a [MAX];
int i,j,n,temp;
printf("enter no. of elements:");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
//sorting
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
printf("sorted elements in ascending order:\n");
for(i=0;i<n;i++)
{
printf("%5d",a[i]);
}
getch();
return 0;
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.