Search C Program | nimishsoft@gmail.com

Bubble Sort

/* Bubble Sort */
#include<stdio.h>

int main()
{
 int arr[10],i,j,t;
 printf("Please enter 10 values:\n");
 for(i=0;i<10;i++)
  scanf("%d",&arr[i]);
 
 for(i=0;i<9;i++)
 {
  for(j=0;j<9-i;j++)
  {
   if (arr[j]>arr[j+1])
   {
    t=arr[j];
    arr[j]=arr[j+1];
    arr[j+1]=t;
   }
  }
 }
 
 printf("Sorted Array is:\n");
 for(i=0;i<10;i++)
  printf("%d\n",arr[i]);
 
 return 0;
}

Related Posts:
-------------------------------------------------------------
Selection Sort
http://cbasicprogram.blogspot.in/2012/05/selection-sort.html

Insertion Sort
http://cbasicprogram.blogspot.in/2012/05/insertion-sort.html

5 comments: