Thursday 9 June 2011

this is sorting program

Write a program in c to sort an unsorted array using bubble sort method?
solution for this is given below :-
#include<stdio.h>
#include<conio.h>
main()
{
int arr[50],temp,i,j,n;
clrscr();
printf("\nEnter any Value less Than 50");
scanf("%d",&n);
printf("\n\tEnter The Values into ARRAY ");
for(i=0;i<n;i++)
{
printf("\n\n Enter Element no %d: ",i+1);
scanf("%d",&arr[i]);
}
for(i=1;i<n;i++)
{
for(j=0;j<n-i;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<n;i++)
{
printf("\n \n \t %d",arr[i]);
}
getch();
}

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home