Wednesday, 2 July 2014

Bubble sort

#include<conio.h>
#include<stdio.h>

main()
{
int n,temp;
puts("enter the size of the array");
scanf("%d",&n);
int arr[n],i,j;
puts("enter values in the array");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<=n;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}

for(i=0;i<=n;i++)
printf("%d",arr[i]);

getch();
return 0;
}

No comments:

Post a Comment