How to Write a C program that receives 10 float numbers from the console and sort them in non-ascending order, and prints the result in C Programming Language ?
Solution:
/*C program that receives 10 float numbers from the console and sort them in non-ascending order, and prints the result*/
#include <stdio.h>
int main() //Program Start
{
float numbers[10],result; //definition of float variables and numbers[10] is a array
int i,p,k; //definition of integer variables
printf("The program take 10 float numbers and organize in decreasing order.\n\n");
//print message to enter 10 numbers
printf("enter 10 numbers:(Note:enter one number and press enter)\n");
for(i=0;i<10;i++) //loop for input
scanf("%f",&numbers[i]); //the input numbers are save in numbers[i]
//print message of the numbers the user enter
printf("Numbers that you enter are:\n %f\n %f\n %f\n %f\n %f\n %f\n %f\n %f\n %f\n
%f\n",numbers[0],numbers[1],numbers[2],numbers[3],numbers[4],numbers[5],numbers[6],numbers[7],
numbers[8],numbers[9]);
//print a message of the numbers in decreasing order
printf("decreasing order:\n");
for(i=10;i>=0;i--) //loop for compare the numbers enter
{ for(k=10;k>=0;k--) //loop for compare the numbers with the array numbers[k]
{ if(numbers[i]<numbers[k]) //compare
{
result=numbers[i]; //save number
numbers[i]=numbers[k]; //save the greater number one after another
numbers[k]=result; } } }
//print the numbers in decreasing number
printf(" %f\n %f\n %f\n %f\n %f\n %f\n %f\n %f\n %f\n
%f\n",numbers[0],numbers[1],numbers[2],numbers[3],numbers[4],numbers[5],numbers[6],numbers[7],
numbers[8],numbers[9]);
// Message to exit the program
printf ("Press any botton and enter\n");
scanf ("%x",&p);
} //end of the program