Thursday, 15 August 2019

C program for sorting


/*Sorting in an ascending order*/


#include<stdio.h>
void
main()
{
            int i,j,n;
            float a[100],t;
            printf("enter the total number of data :");
            scanf("%d",&n);
            printf("enter the data:\n");
            for(i=0;i<n;i++)
                        scanf("%f",&a[i]);
            for(i=0;i<n-1;i++)
            {
                        for(j=i+1;j<=n-1;j++)
                        {
                                    if(a[i]>a[j])
                                    {
                                                t=a[i];
                                                a[i]=a[j];
                                                a[j]=t;
                                    }
                        }
            }
            printf("\n sorted array in ascending order is:\n");
            for(i=0;i<n;i++)
                        printf("%f\n",a[i]);
}

No comments:

Post a Comment

Thanks for comment.