Sorting the given array in Ascending order in C

C Program to sort the given Array in Ascending order

Source code :


#include <stdio.h>

int main(){

int array[] = {1,45,10,35,100,13,147,500,80};
int size = sizeof(array)/sizeof(array[0]);
int i,j,temp;

for (i = 0; i < size ; i++){
    
    for(j = i +1 ; j < size ; j++){
        
        if(array[i] > array[j]){
            temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }
        
    }
    
}


for(i = 0 ; i < size ; i++){
    printf("%d\n",array[i]);
}


return 0;

}

Output :

1
10
13
35
45
80
100
147
500

Output :


                

Comments :