This this my coding, i want to convert it into Descending and output like :
How many marks do you have [1 to 20] ? : 4
Enter mark 1 : 50
Enter mark 2 : 55
Enter mark 3 : 45
Enter mark 4 : 60
The sorted array in ascending order:
45
50
55
60
The sorted array in descending order:
60
55
50
45
The incomplete coding are below, can sumone help me finish it..
Code:#include <stdio.h> #include <conio.h> #define k 20 int main() { int a[k], n, p, j, i, small_j, smallest, biggest, big_j; printf("\nHow many marks do you have [1 to 20] ? : "); if(scanf("%d", &n) == 1 && n>0 && n<=k) { for(j=1; j<n+1; j++) { printf("Enter mark %d : ",j); scanf("%d", &a[j]); } for(p=0; p<n; p++) { smallest = a[p]; small_j = p; for(j=p; j<n+1; j++) if(a[j] < smallest) { smallest = a[j]; small_j = j; } a[small_j] = a[p]; a[p] = smallest; } printf("\nThe sorted array in ascending order:\n"); for(j=0; j<n; j++) printf("%d\n", a[j]); } return 0; }



LinkBack URL
About LinkBacks


