Bubble sorting technique.
■》Program to implement bubble sort in c. language.
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[20],N,p,i,temp;
int counter=0;
clrscr();
printf("Enter the size of array=");
scanf("%d",&N);
printf("Enter the elements=");
for(p=0; p<N; p++)
{
scanf("%d",&arr[p]);
}
printf("before sorting elements are=");
for(p=0; p<N; p++)
{
printf("%d\t",arr[p]);
}
while(counter<N-1)
{
for(i=0; i<N-counter-1; i++)
{
if(arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
counter++;
}
printf("the sorted array elements are=\n");
for(p=0; p<N; p++)
{
printf("%d\t",arr[p]);
}
getch();
}
■》Output->
Comments
Post a Comment