/* Bubble Sort */
#include<stdio.h>
#include<math.h>
int main()
{
float a[100], temp;
int i, j, n;
printf("Enter the # of elements are to be sorted:");
scanf("%d", &n);
printf("---: Put value of the elements :---\n");
for(i=0;i<n;i++)
{
scanf("%f", &a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("----: The sorted list in ascending order is :----\n");
for(i=0;i<n;i++)
{
printf("%f\n", a[i]);
}
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
float a[100], temp;
int i, j, n;
printf("Enter the # of elements are to be sorted:");
scanf("%d", &n);
printf("---: Put value of the elements :---\n");
for(i=0;i<n;i++)
{
scanf("%f", &a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("----: The sorted list in ascending order is :----\n");
for(i=0;i<n;i++)
{
printf("%f\n", a[i]);
}
return(0);
}
Comments
Post a Comment