bubble sort in c
// bubble sort
#include<stdio.h>
int main()
{
int i, j,c,n,array[100],swap;
printf("enter the elements of for which you want to sort:");
scanf("%d",&n);
printf("enter the %d \n elements");
for(i=0;i<n;i++)
{
scanf("%d",&array[i]);
}
for(i=0;i<(n-1);i++)
{
for(j=0;j<(n-i-1);j++)
{
if(array[j]<array[j+1])
{
swap=array[j];
array[j]=array[j+1];
array[j+1]=swap;
}
}
}
printf("sorted list in ascending order:");
for(i=0;i<n;i++)
{
printf("%d\n",array[i]);
}
return 0;
}
Comments
Post a Comment