Suppose we are given an array a such that it contains both even and odd numbers. We have to move the even elements to another array say b and odd elements(numbers) to array c. the numbers in array are to be entered by the user which means we do not know the exact number of even and odd elements present in a. Let us assume that there are 5 even numbers and 5 odd numbers but the size of array b and c is 10. what should we do so that they don''t print garbage value
Jump to Post
There are (at least) 2 easy approaches.
One is to simply keep a count of how many numbers you add to each array, and do not access the array beyond that limit. You will need such a count anyway when you are populating the b&c arrays so that you know …
All 3 Replies
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.