Sunday, August 14, 2011

Bubble sorting in C

#include "stdio.h"


#include "conio.h"

void main()

{

int arr[100],temp,i,n,j;

clrscr();

printf("\nEnter number of elements in array less Than 100 : ");

scanf("%d",&n);

printf("\n\tEnter The Values into ARRAY ");

for(i=0;i

{

printf("\n\n Enter Element no %d: ",i+1);

scanf("%d",&arr[i]);

}

for(i=0;i

{

for(j=0;j

{

if(arr[j] >arr[j+1])

{

temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}

}

}

printf("\n\n-- Sorted Series --");

for(i=0;i

{

printf("\n \n \t %d",arr[i]);

}

getch();





}
 
OUTPUT : -
 
Enter number of elements in array less than 100 : 5
                   
                            Enter the values into ARRAY
Enter element no 1 : 8
 
Enter element no 2 : -6
 
Enter element no 3 : 0
 
Enter element no 4 : 1
 
Enter element no 5: 9
 
--Sorted Series--
         -6
          0
          1
          8
          9

1 comment:

  1. *typing mistake correct it

    for(i=0;i<n-1;i++)
    {
    for(j=0;j<n-i-1;j++)
    {

    ReplyDelete