Make a new start with a new Thought!

NOTE :                // indicates comments.This wont get printed in the output.This is used for for documentation purpose. PROGRAM: #incl...

Bubble sort program

NOTE :
              
// indicates comments.This wont get printed in the output.This is used for for documentation purpose.

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
  int a[100],n,i,j,temp;
  clrscr();
  printf("Enter the size of the array\t:\t");
  scanf("%d",&n);
  printf("\nEnter %d elements\t:\t",n);
  for(i=0;i<n;i++)
  {
     scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++)
  {
    for(j=0;j<n-1;j++)
    {
       if(a[j]>a[j+1])                           //swapping
       {
           temp=a[j];
           a[j]=a[j+1];
           a[j+1]=temp;
       }
    }
  }
  printf("\nAfter Sorting\t:\t");
  for(i=0;i<n;i++)
  {
    printf("%4d",a[i]);
  }
 getch();
}

OUTPUT :

0 comments: