Write a ‘C’ program to accept n numbers from user store these numbers into an array & sort the numbers of an array.

//arrange or sort the array in ascending and descending order

#include<stdio.h>
#include<conio.h>

void main()
{
int t,n,a[50],i,j;
clrscr();
printf("SORTING OF ARRAY\n\n");
printf("Enter the limit:\n");
scanf("%d",&n);
printf("Enter the element:\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])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("\nIn Asending order\n");
for(i=0;i<n;i++)
{
printf("\n%d",a[i]);
}
printf("\nIn Desending order\n");
for(i=n-1;i>=0;i--)
{
printf("\n%d",a[i]);
}
getch();
}

Comments