Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2- Dynamic odds-and-evens Problem Definition Write a program called odds_evens01 that reads a (non-empty) sequence of integers. As for question 1 above, your
Question 2- Dynamic odds-and-evens Problem Definition Write a program called odds_evens01 that reads a (non-empty) sequence of integers. As for question 1 above, your program should first ask for the number of integers to read and dynamically allocate an array just big enough to hold the number of values you read. You should then read in the elements of the array using a loop. Then your program must dynamically allocate two arrays one to hold all the even numbers from the array you have just read and one to hold the odd numbers from the array. Your code must allocate just enough space to each of the arrays to hold the odd and the even numbers. For example, given the input: 3 4 5 6 9 12 8 2 you must allocate an array of 4 values for the odd numbers and an array of 5 values for the even numbers. Your program must then print the values in the odd array and the even array. Test Cases Two test cases for the program are: input 3 4 5 6 9 1 29 1 1 1 2 2 3 8 output 3 5 9 19 1 1 1 3 46 2 2 28 Write two more test cases in a text file called: odds_evens 01.txt and save it in the directory for this practical. Coding Implement the problem definition above in a file called odds_evens 01.c. Compile your program with wall to help improve the quality of your code. Note, you will need to write a dedicated loop just to count the number of odd and even elements there are so you can allocate the arrays for these. Also note, you may find some code from your previous sessions helpful in writing this solution. Make sure you save your code into your week 10practice folder.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Below is a detailed stepbystep guide and implementation of the described problem in C StepbyStep Guide Read the Number of Integers Prompt the user to ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started