TEAM CODING-BCA

BUBBLE SORT

BUBBLE SORT

#include<stdio.h>
#define n 10
int main()
{
int i,arr[n],temp,j;
printf("enter the unsorted array: ");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(j=0;j<n;j++) //no of steps//
{
for(i=0;i<n-1-j;i++) //no of passes//
{

if(arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}
printf("the sorted arr is : ");
for(i=0;i<n;i++)
{
printf("%d \n",arr[i]);
}
return 0;
}

No comments:

Post a Comment