Friday 10 February 2012

how to sort array with fractional numbers


#include<stdio.h>
main()
{
int i,n,j;
float temp,a[10];
printf("enter the limit:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter %d of %d number\n",i+1,n);
scanf("%f",&a[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
printf("sorted numbers are\n");
for(i=0;i<n;i++)

printf("%f\t",a[i]);
}

No comments:

Post a Comment