Bubble sort

 #include <stdio.h>

int main() {

    int a[50]={4,17,9,12,5};

    int i, j, temp;

    for(i=0;i<5;i++){

        for(j=0;j<4-i;j++){

            if(a[j]>a[j+1]){

                temp=a[j];

                a[j]=a[j+1];

                a[j+1]=temp;

            }

        }

    }

    for(i=0;i<5;i++){

        printf("%d ",a[i]);

    }

    return 0;

}

Comments

Popular posts from this blog

Transpose

1 to n without any parameter Recursion

Recursion Factorial