hello!
I am trying to make a code where a user can input numbers and later choose to print them in ascending or descending order, the code compiles fine but I can´t figure out how to print it in order!
I have been looking for hours but found nothing!
thx already, ok, here´s the code:
#include <stdio.h>
#include <stdlib.h>
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int y;
int main(){
int iArray[9] = {0};
int iOption = 0;
int iResponse = 0;
int x = 0;
do {
printf("\nEnter a number: ");
scanf("%d", &iArray[iResponse]);
x++;
} while ( x < 10 );
system("cls");
printf("\tCHOOSE OPTIONS\n");
printf("\n1\tDisplay the numbers from low to high\n");
printf("\n2\tDisplay the numbers from high to low\n");
printf("\nChoose your option: ");
scanf("%d", &iOption);
switch (iOption){
case 1:
system("cls");
qsort(iArray, 10, sizeof(int), compare);
for(y = 0; y < 10; y++) {
printf("\n%d\n", iArray[y]);
}
break;
case 2:
system("cls");
qsort(iArray, 10, sizeof(int), compare);
for (y = 10; y > 0; y--){
printf("\n%d\n", iArray[y]);
}
break;
}//end switch
return 0;
}//end main function