Challenge 1: Remove Even Integers From an Array
Explore how to write a C# function to remove even numbers from an array while maintaining only odd integers. Understand the problem requirements, handle dynamic arrays, and practice returning results in the expected format.
We'll cover the following...
Introduction
Here is a short guide to these challenge lessons.
- The function definition is always given in the problem statement with the expected arguments and function name to be used. If you change the name in the solution, your code will not compile.
- The skeleton code given has a function definition, which only has the
// Write your code herecomment in the body. It is just there as a placeholder. Delete it, and add your code there. - When you get compile-time errors, it will sometimes refer to line numbers and code that you did not write. That is fine; that is just our evaluation code. But rest assured, that our code compiles. When in doubt, refer to the solution given and paste that in.
- Sometimes you are going to have to return from functions in a form that aligns with the test cases. Your solution may not be incorrect but your form of returning might not be what the evaluation code expects. For example, you might return two numbers in an array, but your test cases might expect an array. Watch out for that. Good luck! π
Problem statement
Implement a function removeEven( int[]Arr, int size ), which takes an array arr and its size and removes all the even elements from the given array.
Input
An array with integers and its size is given.
Note: The array that passed to the function has been created dynamically.
Output
The output is an array with only odd integers.
Sample input
Arr = [1,2,4,5,10,6,3]
Sample output
Arr = [1,5,3]
Coding exercise
Take a close look and design a step-by-step algorithm before jumping in to the implementation. This problem is designed for your practice. Try to solve it on your own first. If you get stuck, you can always refer to the solution provided in the solution section. Good Luck!