top of page

C Program for sorting using Bubble Sort

  • Writer: Jino Shaji
    Jino Shaji
  • Jan 2, 2015
  • 1 min read

Updated: Jun 9, 2020


 #include
#include
void bubble_sort(int [],int);
void main()
{
 int A[30],i,n,j,temp;
 clrscr();
 printf(“Enter The Number Of Elements\n”);
 scanf(“%d”,&n);
 printf(“Enter The Elements\n”);
 for(i=0;i<n;i++)
                scanf(“%d”,&A[i]);
 bubble_sort(A,n);
 printf(“Sorted List\n”);
 for(i=0;i<n;i++)
                printf(“%d\n”,A[i]);
 getch();
}
void bubble_sort(int A[],int n)
{
 int i,j,temp;
 for(i=0;i<n-1;i++)
                {
                for(j=0;j<n-i;j++)
                 {
                                if(A[j+1]<A[j])
                                 {
                                                temp=A[j];
                                                A[j]=A[j+1];
                                                A[j+1]=temp;
                                 }
                                }
                 }
 }

Output


 
 
 

Comentarios


bottom of page