Question: Download program lab2C2.c and start from there. The provided code creates an integer array of size 10 and then filled it with randomly generated integers
Download program lab2C2.c and start from there. The provided code creates an integer array of size 10 and then filled it with randomly generated integers in the range of [0, 40], musing C library function rand() Observe how the program uses #define to define a constant size for array, in order to avoid magic numbers which is considered bad practices, as mentioned in class. Follow the comments to complete the program: Define two more arrays of the same size as arr, to store possible even numbers and prime numbers. Dont use magic number 40 for sizes. You may also need other variables. Use a loop to scan the array, and if an element in the array is an even number, put it into the array of even numbers. If the element is a prime number, then put into the array of red 373 % Submit your program by issuing submit 2031M lab2 lab2C.c 7 prime numbers. A prime number is a whole number that is greater than 1 and can only be divided by 1 and itself. E.g., 2, 3, 5, 7 are prime numbers whereas 4, 6 are not. In order to determine if a number is a prime number, define a boolean function int isPrime(int n) which returns true is n is a prime number and returns false if n is not a prime number. Put the definition of the function after the main() function. Finally, outputs the information about even numbers and prime numbers as shown in the sample output. red 310 % gcc lab2C2.c red 311 % a.out array [ 31 39 19 5 18 9 13 34 0 37 ] 3 even numbers: 18 34 0 5 prime numbers: 31 19 5 13 37 red 312 % a.out array [ 28 11 29 1 0 6 38 22 34 2 ] 7 even numbers: 28 0 6 38 22 34 2 3 prime numbers: 11 29 2 red 313 % a.out array [ 10 12 23 0 5 7 36 15 40 8 ] 6 even numbers: 10 12 0 36 40 8 3 prime numbers: 23 5 7 red 314 % a.out array [ 22 22 19 5 30 39 3 4 28 20 ] 6 even numbers: 22 22 30 4 28 20 3 prime numbers: 19 5 3 red 315 % a.out array [ 39 30 30 22 4 2 13 5 19 16 ] 6 even numbers: 30 30 22 4 2 16 4 prime numbers: 2 13 5 19 red 316 % a.out array [ 31 40 18 12 18 27 24 26 36 3 ] 7 even numbers: 40 18 12 18 24 26 36 2 prime numbers: 31 3 red 317 %
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
