Professional Documents
Culture Documents
Bubble Sort PDF
Bubble Sort PDF
h>
#include<conio.h>
void main()
{
int n, A[100],temp,j;
printf("Enter the number of elements: ");
scanf("%d", & n);
scanf("%d",&A[i]);
for(int i=0;i<n-1;i++)
{
int flag=0;
for( j=0;j<=n-1-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("Sorted list in ascending order:\n");
for ( j = 0; j < n; j++)
printf("%d\n", A[j]);
getch();
}