Bubble Sort  (Data Structures in C)

Bubble Sort (Data Structures in C)


 #include <stdio.h>
 #include <conio.h>


int main() {
 int i,j,k,n,temp,arr[12],echg;

    printf("enter the number of elements:");
    scanf("\n%d",&n);
    printf("enter the elements : ");

    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);

    }
     for(i=0;i<n;i++)
     {
      echg=0;
     printf("\n %d",i);
     for(j=0;j<n-1;j++)
     {
         printf("\n j=%d",j);
         if(arr[j]>arr[j+1])
         {
             temp=arr[j];
             arr[j]=arr[j+1];
             arr[j+1] = temp;
             echg++;
         }


     for(k=0;k<n;k++)
     printf("\t %d \t",arr[k]);
     }

     if(echg==0)
     break;
    }

     printf("\n the array sorted in the ascending order is: ");
     for(i=0;i<n;i++)
     printf("\n%d",arr[i]);
     return 0;
    }