Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Bubble Sort

#include <stdio.h>
int main() {
    int a[100],i,j,n;
    scanf("%d",&n);
    for (i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    for (i = 0; i < n-1; i++){
        for (j = 0; j < n - 1 - i; j++){
            if (a[j]>a[j+1]){
                int temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }
    for (i = 0; i < n; i++){
        printf("%d ",a[i]);
    }
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.