Program For Sorting | general c programs |


Program For Sorting
#include<stdio.h>
#include<conio.h>
main()
{
int a[50],n,i,j,t;
clrscr();
printf("input the no of items u want to sort\n");
scanf("%d",&n);
printf("input the value's to be sorted\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);

}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{

if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("the sorted elements are\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
getch();
}

No comments:

Post a Comment