C program that receives 10 float numbers from the console and sort them in nonascending order

Posted by Samath
  1069
June 01, 2015

 

Write a C program that receives 10 float numbers from the console and sort them in nonascending order, and prints the result.

#include <stdio.h>
int main(int argc, char *argv[]) 
{
	float nums[10],temp; 

	
	for(int i=0;i<10;i++)
	{
		printf("Enter num: ");
		scanf("%f",&nums[i]); 
	}

	printf("Descending Order:\n");
	for(int i=10;i>=0;i--) 
	{ 
		for(int k=10;k>=0;k--) 
		{ 
			if(nums[i]<nums[k]) 
			{
				temp=nums[i]; 
				nums[i]=nums[k];
				nums[k]=temp; 
			}
		 } 
	 }


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