CAN SOMEONE HELP ME PLEASE.
AnakNgDiyos (2)

Scenario
Write a program that sorts ten floating-point numbers in descending order. In this case, the data in the array is initialized (in the code
below). The algorithm is described in Chapter 4.3. After each execution of the inner loop, your program should print the values on the
screen (with another small loop). You can use the "%.2f" format in printf. Your version of the program must print the same result as the
expected output.

#include <stdio.h>
int main()
{
float numbers[10] = {5.6, 4.3, 6.2, 6.4, 7.3, 2.3, 8.3, 9.2, 0.1, 1.9};
/ your code /
return 0;
}

Example output
5.60 6.20 6.40 7.30 4.30 8.30 9.20 2.30 1.90 0.10
6.20 6.40 7.30 5.60 8.30 9.20 4.30 2.30 1.90 0.10
6.40 7.30 6.20 8.30 9.20 5.60 4.30 2.30 1.90 0.10
7.30 6.40 8.30 9.20 6.20 5.60 4.30 2.30 1.90 0.10
7.30 8.30 9.20 6.40 6.20 5.60 4.30 2.30 1.90 0.10
8.30 9.20 7.30 6.40 6.20 5.60 4.30 2.30 1.90 0.10
9.20 8.30 7.30 6.40 6.20 5.60 4.30 2.30 1.90 0.10
9.20 8.30 7.30 6.40 6.20 5.60 4.30 2.30 1.90 0.10
9.20 8.30 7.30 6.40 6.20 5.60 4.30 2.30 1.90 0.10

You are viewing a single comment. View All
KelvinVerhey (18)

There are few problems you need to address.

  1. C has no way to expose length of arrays, or things that are array-like for instance strings. You must either use a function or #define a macro that can use sizeof() or statically code your length in a variable or hard code the limit inside of an expression such as a for loop.

  2. Basic understanding of stdio.h functions would be useful, but not required. You can refer here for a typical standardised include reference for it.

https://pubs.opengroup.org/onlinepubs/7908799/xsh/stdio.h.html

This will allow you to access the printf() function.

https://pubs.opengroup.org/onlinepubs/7908799/xsh/printf.html

3a. For loops. https://beginnersbook.com/2014/01/c-for-loop/
3b. While loops. https://beginnersbook.com/2014/01/c-while-loop/
3c. Do/While loop. https://beginnersbook.com/2014/01/c-dowhile-loop/

  1. If statements for basic expression logic to test conditions for if you're going need to perform a swap of numbers.

https://beginnersbook.com/2014/01/c-if-statement/

That reference is quite crude, but will equip you with at least enough to complete the assignment.

  1. Writing a swap algorithm for the array of numbers so you can trade positions of numbers while you are looping across them to determine if you need to swap them to get your descending order.

  2. Operators of greater and less than to be able to figure out your expression. Depending how you write your if expression you will need one of those to get your correct sorting order.

  3. How arrays work. https://beginnersbook.com/2014/01/c-arrays-example/

This is an example sorting ascending.

https://www.youtube.com/watch?v=nmhjrI-aW5o

You will still need to address your correct sorting order, and outputting the series of floating points numbers. It would be best to address your progress here instead of taking it offsite, so others can learn from your progress.

mwilki7 (184)

@KelvinVerhey this problem contains a constant-sized array so I don't think he should have trouble with that