Question: Please write this program in C. The objective is to create a program which will dynamically allocate space for an array made of doubles, using

Please write this program in C.

The objective is to create a program which will dynamically allocate space for an array made of doubles, using user input size. The array will then be filled with values given from user input and then this array will be sorted using the insertion sort algorithm.

The user should be asked to enter the number of elements for the array (positive integer). Space should be dynamically allocated by the program for an array comprised of doubles that can store n elements. The user should be asked to enter a double value for each corresponding element, one at a time. Each double value entered should be stored in the array, in the order that they were input. There is no need for input validation, assume only positive double values are input.

Once the user has entered all the required values, the unsorted array should be printed ( 2 decimal digits of precision for each value). The insertion sort should then be used to sort the array from highest to lowest and then the sorted array should be printed (2 digits of precision). The dynamically allocated memory should then be freed.

It is very important for the array to be dynamically allocated and then the memory freed.

The program should run identically or almost identical to this example:

Please write this program in C. The objective is to create a

Enter the numbers of elements: 8 Enter element 0: 9.4 Enter element 1: 4.5 Enter element 2: 1.5 Enter element 3: 9.5 Enter element 4: 2.3 Enter element 5: 4.5 Enter element 6: 6.7 Enter element 7: 5.7 Unsorted array: 9.40 4.50 1.50 9.50 2.30 4.50 6.70 5.70 Sorted array: 9.50 9.40 6.70 5.70 4.50 4.50 2.30 1.50

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!