Advertisement
Sabbir-bin

Bubble_Sort

Feb 2nd, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3.  
  4. {
  5.   int i, j, a[10],n,temp;
  6.  
  7.   printf("enter the value :");
  8.   scanf("%d", &n);
  9.  
  10.    printf("enter the element of array: ");
  11.  
  12.    for(i=0; i<n; i++)
  13.    scanf("%d", &a[i]);
  14.  
  15.     for(i=0; i<n-1; i++)  //loop for items
  16.   {
  17.     for(j=0; j<n-i; j++) // lop for inside the items
  18.     {
  19.       if(a[j]> a[j+1])
  20.       {
  21.         temp=a[j];
  22.         a[j ]=a[j+1];   //sawping the temp value
  23.         a[j+1]=temp;
  24.       }
  25.     }
  26.   }
  27.  
  28.   for(i=0; i<n; i++)
  29.  
  30.     printf("%d", a[i]);
  31.  
  32.  
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement