Advertisement
rana1704

Bubble sort

Jun 16th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int a[50],i,n,j,temp;
  5.     scanf("%d",&n);
  6.     for(i=0;i<n;i++)
  7.     {
  8.         scanf("%d",&a[i]);
  9.     }
  10.  
  11.     for(j=0;j<n;j++)
  12.     for(i=0;i<n-j-1;i++)
  13.     {
  14.         if(a[i]>a[i+1])
  15.         {
  16.             temp=a[i];
  17.             a[i]=a[i+1];
  18.             a[i+1]=temp;
  19.         }
  20.     }
  21.  
  22.     for(i=0;i<n;i++)
  23.          printf("%d\t",a[i]);
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement