Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




Program to perform BUBBLE SORT in C++

Download Attachment
/********************************/
/*PROGRAM TO PREFORM BUBBLE SORT*/
/********************************/



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

void main()
{
int a[10],n,i,j,temp,flag;
clrscr();
printf("Enter the size of array: ");
scanf("%d",&n);
printf("\nEnter the elements of array:\n");

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

for(i= 0 ; i < n-1; i++)
{
flag=0;
for( j = 0; j < n-i ; j++)
{

if(a [ j ] > a [ j + 1 ] )
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
flag=1;
}
}

if(flag==0)
{
break;
}
}

printf(" \n After sorting the elements of array are: \n ");
for( i = 0 ; i < n ; i++ )
{
printf(" %d ",a [ i ]);
}
getch();
}

Share this article   |    Print    |    Article read by 689 times
Author:
Rohit kakria
I am software developer
Related Articles:
Related Interview Questions: No related interview question