Program for sorting of array element using bubble sort in C
Program for sorting of array element using bubble sort in C
What is sorting ?
The term sorting means arrangement of element in particular order i.e in ascending or descending order is known as sorting.Example:: 45,55,25,35,65
Sorted data :: 25,35,45,55,65
How bubble sort work ?
Bubble sort method works on method of comparing two consecutive digits.45,55,25,35,65
working::
45,55,25,35,65
45,25,55,35,65
25,45,55,35,65
25,45,35,55,65
25,35,45,55,65
( sorted data )
Program for bubble sort in c
#include<stdio.h>#include<conio.h>
void main ()
{
int i,j,n,t,a[100];
clrscr ();
printf ("\n Enter size of array:");
scanf ("%d", &n);
printf ("\n Enter element in array:");
for (i=0;i<n;i++)
{
scanf ("%d", &a[i]);
}
for (i=o;i<n-1;i++)
{
for (j=0;j<n-i-1;j++)
{
if (a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf (sorted array=");
for (i=0;i<n;i++)
{
printf ("\t %d",a[i]);
}
getch ();
}
Comments
Post a Comment
Thank You for your participation..