5/18/2016

C Program For Sort A Float Array In Acceding And Descending Order Using For Loop

Problem :- C Program For Sort A Float Array In Acceding And Descending Order Using For Loop

Array:-Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Solution :-

#include<stdio.h>

main()
{
int i,n=11,j;
float temp=0.0f;

float a[11] = {1.01,6.66,3.3,7.5,2.2,4.1,7.9,9.7,0.01,9.14,0.69};

printf("\nSorting A Float Array \n");

printf("\n\nElement Before Sorting \n\n");

for(i= 0; i<=10; i++) 
{
    printf("%.2f  ", a[i]);
}

printf("\n");

printf("\n\nElement After Sorting \n\n");

for(i=0;i<n;i++)
{
    for(j=0;j<n-i-1;j++)
    {
        if(a[j]>a[j+1])
        {
            temp=a[j+1];//swaping element 
            a[j+1]=a[j];
            a[j]=temp;
        }
    }
}
//printing output of program
for(i= 0; i< 11; i++) 
{
    printf("%.2f  ", a[i]);
}
printf("\n\n");
}

Output:-

C Program For Sort A Float Array In Acceding And Descending Order Using For Loop

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment