Question: Program in C Write a progran that dynamically allocates an array of integers. The size of the array (the number of integers, not the byte

Program in C
Write a progran that dynamically allocates an array of integers. The size of the array (the number of integers, not the byte size should be read from the user uing scanf You nay assure that the user will input a positive integer (i.e., don't do error checking). The elemente of the array ahould be filled using random function After filling the array with random numbers, your program should then make a copy of the array, and sort the ne array in asconding order: that is, the first entry of the array should contain the smallest integer in the array, while the last entry shouled contain the largest integer in the array. Then make a second copy of the original array, and sort it in descending oraer inally your progran should print out all three arrays. All three arrays ahould be aeparately allocated using malloc library function Don't forget to call free 0 to deallocate the arrays You should always check the return value of malloc, and if it's NULL, print an error message and quit the program, like this: p-malloc (1000000000) perror "malloc reurned NULL" exit(1); Make sure you do this everytine you call mallac all labs in this class This applies to please name your executa le program "Lort" Type "man 3 randonto read the nan page Eor randomIn xR2, there is no mention of random(). Instead, it describes the older and inferior rand() function The usage is the sane. Use random in your code The random function returns a non-negative integer in the range froa 0 to 2*31-1. In order to make the visual inspection of the output a little easier, l convert the large random integer to one in the range from to 99. Please print the arrays in the following fornat: original: 31 57 1 44 ascending: 1 31 44 57 descending: 57 44 31 1 You will notice that random function always returns the sane gequence of integers. It's just a peeudo-randon aumber generator tha: sinulates randomness. You can "seed" the randon number generator by calling srandon) function once in the beginning of your program Calling it with the retur value of time (NULL) ill ensure a differen gequence of random numbers everytime the progran is run You should do that For sorting, you have two options . You can implement any orting algorithm yourself. You are allowed to look up on the Internet or any book Eor a sorting algorithn you do, please cite the sourcc in the conent for the Eunction Or you can use qsort function provided by the standard C library iust like they provide printEO Using the qsort 1ibrary function is simpler, but requires that you know ho to use pointers to functions, ich we have not covered yet. Section 5.11 of K&R2 describes pointers to functions. Unfortunately, the section uses a sorting funetion named "qsort" o illustrate pointers to functions, but it takes a different get of paraneers than the real gsort() *f standard library. The standard library version of qsorto is described on page 253, K&R2, or in the man page (type "man qsort There is, however, one little requirement about calling the sorting function, whether it's your own function or the qsort0 function.I want you to call your sorting function indireetly through the following function: /1 Thi function sorts an integer array begin points to the 1st element of the array end points to ONE PAST the last element of the array If ascending is 1, the array vill be sorted in ascending order If ascending is 0, the array ill be sorted in descending order void sort integer_arrayint begin, int ed, int ascending) In here, you will call your real sorting function you own " or the qsorto.Basically, I want to make sure that you know how to translate the begin/end paraneter to whatever , i reguired for your sorting function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
