Friday, 24 February 2012

bubble sort algorithm programme in c


/*sorting of an array in ascending  order*/
#include<stdio.h>
#include<string.h>


void main()
{
int arr[5],i,temp;
static int j=0;
printf("enter any 5 number");


   while( j !=4)  //get the value from user at run time
    {
      scanf("%d",&arr[j]);
      printf("Enterd value is %d in index %d",arr[j],j);
    j++; 
   }


printf("After sorting algorithm value is");
for(i=0;i<10;)
{
  for(j=0;j<=4;)
  {
   if(arr[j]>arr[j+1]) //logic for sorting
    {
     temp=arr[j];  //check the first and second position if true
     arr[j]=arr[j+1]; //swap the value
     arr[j+1]=temp;
    } 
   j++;
  }  
  i++;
}   
   for(j=0;j<=4;j++)
     {
       printf("\t%d",arr[j]);   
      }
}//end of main

No comments:

Post a Comment

Compiler for C,C++ and Python {paste your programme to see the output}