Bubble Sort
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; }