Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE THE GIVEN CODE BELOW #include #include #include #define SIZE 10 main () { int i; int arr[SIZE]; srand(time(0)); for( i = 0; i

image text in transcribed PLEASE USE THE GIVEN CODE BELOW #include  #include  #include  #define SIZE 10 main () { int i; int arr[SIZE]; srand(time(0)); for( i = 0; i  4. Problem C2 branches, loops and integer arrays (20 pts) Specification Write an ANSI-C program that generates array of random integers, and then determines and displays all even numbers and prime numbers in the array. Implementation - 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. Don't 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 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 is Prime (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. Sample Inputs/Outputs: (note due to randomness, each run generates different results.) red 310 gcc 1ab2C2.c red 311a.out array [ [ 31391951891334037] 3 even numbers: 18340 5 prime numbers: 311951337 red 312 ; a.out array [ [ 2811291063822342] 7 even numbers: 28063822342 3 prime numbers: 11292 red 313 a.out array [ [ 1012230573615408] 6 even numbers: 1012036408 3 prime numbers: 2357 red 314 a.out array [[ 22221953039342820] 6 even numbers: 22223042820 3 prime numbers: 1953 red 315 \% a.out array [ [ 39303022421351916] 6 even numbers: 3030224216 4 prime numbers: 213519 red 316 a.out array [ [ 3140181218272426363] 7 even numbers: 40181218242636 2 prime numbers: 313 red 317%

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

7. I am optimistic about my future.

Answered: 1 week ago

Question

Explain the forces that influence how people handle conflict

Answered: 1 week ago