logo CodeStepByStep logo

Split

Language/Type: C# arrays array traversals

Write a method named Split that accepts an array of integers as a parameter and returns a new array twice as large as the original, replacing every integer from the original array with a pair of integers, each half the original. If a number in the original array is odd, then the first number in the new pair should be one higher than the second so that the sum equals the original number. For example, if a variable named a refers to an array storing the values {18, 7, 4, 24, 11}, the call of Split(a) should return a new array containing {9, 9, 4, 3, 2, 2, 12, 12, 6, 5}. (The number 18 is Split into the pair 9, 9, the number 7 is Split into 4, 3, the number 4 is Split into 2, 2, the number 24 is Split into 12, 12 and the number 11 is Split into 6, 5.)

Method: Write a C# method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.