Question 2- Dynamic odds-and-evens Problem Definition Write a program called odds_evens01 that reads a (non-empty) sequence...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Concepts of Database Management
ISBN: 978-1285427102
8th edition
Authors: Philip J. Pratt, Mary Z. Last
Posted Date:
Students also viewed these programming questions
-
Examine the following program: class Exercise1 { public static void main (String[] args ) { int[] val = {0, 1, 2, 3}; sum = System.out.println( "Sum of all numbers = " + sum ); } } Complete the...
-
What will be the sum of third proportional to 18 and 54 and fourth proportional to 12, 18 and LCM of 12 and 18? 1. 162 2. 216 3. 612 4. 256 526 5.
-
Mr. S was fired from his job because of unprofessional conduct. He believed that his reputation in the local business community was damaged and that he should make a new start in a different state....
-
A manufacturer has been purchasing raw materials from a supplier whose consignments have a variance of 15.4 (in squared pounds) in impurity levels. A rival supplier claims that she can supply...
-
In addition to the quantitative variable pesticide concentration, the researchers also report whether or not the pesticide was detected in the urine (at standard detection levels). Before the...
-
The Byrd Company had the following transactions during 2007 and 2008: 1. On December 24, 2007 a computer was purchased on account from Computers International for $60,000. Terms of the sale were...
-
A 0.55 kg block of ice is sliding by you on a very slippery floor at 3.5 m/s. As it goes by, you give it a kick perpendicular to its path. Your foot is in contact with the ice block for 0.0035...
-
Select an organization you are familiar with or have worked for (currently or in the past). You are tasked with analyzing the organization both internally and externally. You are also tasked with...
-
B Marcovich pays cash for three vehicles on 2 January 2023 for $38 500 ($35 000 + $3500 GST) each. Motor vehicle 1 will be replaced after five years and has an estimated residual of $2200 ($2000 +...
-
R Gilmour & Associates purchased and installed on credit a computer system that was commissioned on 1 April 2021 for $66 000 ($60 000 + $6000 GST). It is expected that the computer system has a...
-
Consider the construction of a trinomial tree for the general short rate model of form dy t = ((t) yt)dt + dW t, r t = g (yt). The approach typically involves constructing the tree for dx t = KX t...
-
The accounts of P L Lorikeet revealed a number of matters that require attention and correction by general journal. a Cash receipts journal totals for the month were posted to the general ledger only...
-
Assume a two-factor APT model is appropriate for asset returns, and there are an infinite number of assets in the economy. Two factors drive expected return: the percentage change in GDP and interest...
-
On May 8, 1984, Hannah Eisenstat graduated from Louisiana State University. She set to work opening a coffee shop in Baton Rouge called HannaH and found a perfect location in a new development. Using...
-
Read the case study Richter: Information Technology at Hungarys Largest Pharma and answer the following question: How does the organization ensure the accuracy of the data it stores?
-
Under what circumstances would you not need to break down an overall design into a consideration of individual user views?
-
What are triggers? What purpose do they serve? How do you gain the functionality of a trigger using Access 2013?
-
The management of Colonial Adventure Tours wants you to complete the following exercises. You do not use the Colonial Adventure Tours database for any of these exercises. 1. The DBA asks for your...
-
What percentage of women have red blood cell counts in the normal range from 4.2 to 5.4? Assume that red blood cell counts of women are normally distributed with a mean of 4.577 and a standard...
-
Find P 80 , the 80th percentile for the red blood cell counts of women.
-
A new integrated circuit board is being developed for use in computers. In the early stages of development, a lack of quality control results in a 0.2 probability that a manufactured integrated...
Study smarter with the SolutionInn App