Bubble Sort - The easiest sort in C language


SUBMITTED BY: Neutrino

DATE: Dec. 10, 2020, 3:38 a.m.

FORMAT: Text only

SIZE: 444 Bytes

HITS: 493

  1. #include<stdio.h>
  2. int main(void)
  3. {
  4. int i,n,temp,j,arr[10];
  5. printf("\nEnter the no of elements in the array ");
  6. scanf("%d",&n);
  7. printf("\nEnter the elements ");
  8. for(i=0;i<n;i++)
  9. {scanf("%d",&arr[i]);}
  10. for(i=0;i<n;i++)
  11. {
  12. for(j=0;j<n-i-1;j++)
  13. {if(arr[j]>arr[j+1])
  14. {
  15. temp=arr[j];
  16. arr[j]=arr[j+1];
  17. arr[j+1]=temp;
  18. }
  19. }
  20. }
  21. printf("\n The array sorted in ascending order ");
  22. for(i=0;i<n;i++)
  23. {printf("%d\t",arr[i]);}
  24. return 0;
  25. }

comments powered by Disqus