C Program For BB Sort

/*bb sort*/


#include<stdio.h>
#include<conio.h>
void main(void)
{
int a[10],n,i,j,temp;
clrscr();
printf("Enter the number of values");
scanf("%d",&n);
 for(i=0;i<n;i++)
 {
 printf("Enter the value");
 scanf("%d",&a[i]);
 }

 printf("The array before sorting is\n");

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

 for(i=0;i<n;i++)
 {
  for(j=0;j<n-i-1;j++)
  {
   if (a[j]>a[j+1])
   {
   temp=a[j];
   a[j]=a[j+1];
   a[j+1]=temp;
   }
  }
 }

 printf("The array after sorting is\n");

 for(i=0;i<n;i++)
 {
 printf("a[%d]=%d\n",i,a[i]);
 }
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment