Sorting array in Ascending and Descending order in C

Source code :

#include <stdio.h>

int main() {
    int i,j,temp;
    
    int data[10] = {5,10,2,3,15,89,1,0,4,20};
    
    for (i=0;i<10;i++) {
        for (j=i+1;j<10;j++) {
               if (data[i]>data[j]) {
                    temp = data[i];
                    data[i] = data[j];
                    data[j] = temp;
                }
          }
    }
    
    
    printf("Ascending Order:\n");
    
    for (i=0;i<10;i++)
            printf("%d\n",data[i]);
            
            
    printf("\nDescending Order:\n");
    
    for (i=10-1;i>=0;i--)
            printf("%d\n",data[i]);
            
    return 0;
}

Output :

Ascending Order:
0
1
2
3
4
5
10
15
20
89

Descending Order:
89
20
15
10
5
4
3
2
1
0

Output :


                

Comments :