Question: Can tou solve Task 2.1 C programming language Thanks for h Consider the following C programs that randomly generates an integer array between 1 and
Can tou solve Task 2.1
C programming language
Thanks for h
Consider the following C programs that randomly generates an integer array between 1 and 100 and then filter it and distinguish even and odd numbers in separate arrays. Note that, all arrays must end with a zero value. Task 2.1: define the function int " generateArray (int min, int max, int length) ( that generates an array of random numbers between min and max with a specific length and then returns the array (the pointer of the array). Since this is a function, the created array must be allocated in the memory dynamically using malloc function (which returns vold *), because otherwise, it will be crased once the function tinishes execution. To generate dynamically allocated elements (array) in the memory we do the following: int myArray =( int ) malloc ( sizeof(int ) length ); The above generates 4x length places and then casts it to integer type using (int ) because the function is required to generate an integer array and return it. To access the locations of this array, we use the addition style (not the index style for static arrays). For example, to access the first element of the location we simply do: (myArray+)=min+rand()%(maxmin+1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
