C Source Codes List | Source Code Home
Program : Program to sort any no. of numeral i/p in ascending or descending order.
/* Prg. to sort any no. of numeral i/p in ascending or descending order */
#include
void sort(void);
int c,a[20],l;
void main()
{
clrscr();
printf("Enter no. of elements in the list:- ");
scanf ("%d",&l);
printf("\nCHOICE:-");
printf("\n(1) Sort in ascending order.");
printf("\n(2) Sort in descending order.");
printf("\nCHOICE:- ");
scanf("%d",&c);
if (c!=1 && c!=2)
{
printf("\nERROR");
getch();
exit(0);
}
sort();
getch();
}
void sort(void)
{
int n,i,j,temp=0,min,k;
for (i=1;i<=l;i++)
{
printf("\nEnter no.:- ");
scanf("%d",&a[i]);
}
for (i=1;i<=(l-1);i++)
{
min=a[i];
k=i;
for (j=(i+1);j<=l;j++)
{
if (a[j]=1;i--)
printf("\n%d",a[i]);
break;
default:
printf("\nERROR");
}
return;
}
C Source Codes List | Source Code Home
|
|