Bubble Sort

From Ta Wiki
Revision as of 23:59, 7 March 2019 by Tata (talk | contribs) (Created page with "<pre> #include<stdio.h> int main(){ int arr[10000],n,i,j,temp; printf("Enter number of numbers : "); scanf("%d",&n); printf("Enter %d numbers : ",n); for(i...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#include<stdio.h>
int main(){
    int arr[10000],n,i,j,temp;
    printf("Enter number of numbers : ");
    scanf("%d",&n);
    printf("Enter %d numbers : ",n);
    for(i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }

    //-------- SORT --------
    for(i=0;i<n-1;i++){
        for(j=0;j<n-1-i;j++){
            if(arr[j]>arr[j+1]){
                temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
            }
        }
    }
    //----------------------

    printf("Sorted List : ");
    for(i=0;i<n;i++){
        printf("%d ",arr[i]);
    }
    
    scanf(" ");
    return 0;
}