img
Question:
Published on: 12 October, 2024

Implement Bubble Sort using C.

Answer:
#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
	int a[100],i,n,j,temp; 
	clrscr(); 
	printf("\n\n\n\t\t ********** BUBBLE SORT **********\n\n\n"); 
	printf("Enter the no of digit to be sorted ...... "); 
	scanf("%d",&n); printf("\nEnter the number...>> "); 
	for(i=0;i<=n-1;i++) 
{ 
	scanf("%d",&a[i]); 
}
printf("\nThe Sorted no is as follows.....>>>>\n\n\t\t\t"); 
for(i=0;i<=n-1;i++) 
{
 	for(j=0;j<=n-1;j++) 
{ 
if(a[j]>a[j+1]) 
{ 
temp = a[j]; 
a[j] = a[j+1]; 
a[j+1] = temp; 
} 
} 
} 
for(i=0;i<=n-1;i++) 
{ 
	printf("%d ",a[i]); 
} 
getch(); 
}

 

 
Random questions