Written by Kousik
/* c program for bubble sort*/
#include<stdio.h>
int a[20];
void bubble(int n)
{
int t, i,j;
for(j=n-1;j>0;j++)
{
for(i=0;i<j;i++)
{
if(a[i+1]>a[i])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
}
int main()
{
int n,i;
printf("Enter the total number of elements: ");
scanf("%d",&n);
printf("Enter the values: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
bubble(n);
printf("The sorted sequence: ");
for(i=0;i<n;i++)
printf(" %d",a[i]);
return 0;
}
0 comments:
Post a Comment