Write a C Program to Sort an Array in Ascending And Descending Order Using For Loop. Arrays are a kind of data structure that can store a fixed-size sequential collection of elements of the same type. Program to Sort float array in C. 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. Float array in C Programming language.

C Program to Sort an Array in Ascending And Descending Order
#include <stdio.h>
main()
{
	int i, n = 11, j;
	float temp = 0.0 f;
	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("\nC Program to Sort an 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];	
				a[j + 1] = a[j];
				a[j] = temp;
			}
		}
	}
	
	for (i = 0; i < 11; i++)
	{
		printf("%.2f  ", a[i]);
	}
	printf("\n\n");
}
The Output of C Program to Sort an Array
Similar to Sort an Array
0 Comments: