Write a C program to sort a list of N elements using Bubble sort Technique

#include<stdio.h>
#include<conio.h>
void main()
{
 int i,n,j,a[30],temp;
 clrscr();
 printf("enter the number of elements :");
 scanf("%d",&n);
 printf("enter the elements of the list:\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 printf("\n\n BUBBLE SORT \n\n");
 printf("\n orginal order \n ");
  printf(" * * * * * * * * * \n");
 for(i=0;i<n;i++)
  printf("%d\t",a[i]);

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

 printf("\n\n SORTED ORDER  \n");
 printf("* * * * * * * * * * \n");
 for(i=0;i<n;i++)
 printf("%d\t",a[i]);
 printf("\n * * * * * * * * * * * \n");
 getch();
 }

No comments:

Post a Comment