Q:

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

belongs to collection: Loops C Programs for Practice

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#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:

Sorting A Float Array

Element Before Sorting 

1.01  6.66  3.30  7.50  2.20  4.10  7.90  9.70  0.01  9.14  0.69  

Element After Sorting 

0.01  0.69  1.01  2.20  3.30  4.10  6.66  7.50  7.90  9.14  9.70  

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program For Denomination of an Amount Using Whil... >>
<< C Program To Check Number Is Divisible By 11 Or No...