Write a program that sorts an array of integers into ascending order or descendi
ID: 3622315 • Letter: W
Question
Write a program that sorts an array of integers into ascending order or descending order. Use command-line arguments to pass either argument -a for ascending order or -d for descending order. [Note: This is the standard format for passing options to a program in UNIX.]
This is what I got:
#include
#include
int main(void){
int i,x;
int a[20];
srand(time(NULL));
for(i=1;i<=20;i++)
{
a[i] = 1 + rand()%1000;
printf("%d = %d ",i,a[i]);
}/* end for*/
}/* end main */
But, I don't get how to sort the array in ascending or descending order and how to use command-line argument.