Code:
#include <stdio.h>
void sortdescending(int u[], int n);
void sortascending(int u[], int n);
int main(void)
{
int u[]={333,111,444,555,999};
int n=sizeof(u)/sizeof(int);
int k;
int choice;
printf("Press 1 to sort in ascending order\n");
printf("Press 2 to sort in descending order\n");
scanf("%d", &choice);
if (choice == 1)
{
sortascending(u,n);
}
else
{
sortdescending(u,n);
}
for (k=0;k<n;k++)
printf("%d\n", u[k]);
return 0;
}
void sortdescending(int u[], int n)
{
int i,j,tmp;
for (i=1;i<n;i++)
for (j=i;j>0;j--)
{
if (u[j]> u[j-1])
{
tmp=u[j];
u[j]=u[j-1];
u[j-1]=tmp;
}
else break;
}
return;
}
void sortascending(int u[], int n)
{
int i,j,tmp;
for (i=1;i<n;i++)
for (j=i;j>0;j--)
{
if (u[j]< u[j-1])
{
tmp=u[j];
u[j]=u[j-1];
u[j-1]=tmp;
}
else break;
}
return;
}
or something of the like.