logo CodeStepByStep logo

Stretch

Language/Type: C# List collections
Related Links:

Write a method named Stretch that accepts as a parameter a List of integers, and modifies it to be twice as large, replacing every integer with a pair of integers, each half the original. If a number in the original list 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 v refers to a list storing the values {18, 7, 4, 24, 11}, the call of Stretch(v); should change v to contain {9, 9, 4, 3, 2, 2, 12, 12, 6, 5}. (The number 18 is Stretched into the pair 9, 9, the number 7 is Stretched into 4, 3, the number 4 is Stretched into 2, 2, the number 24 is Stretched into 12, 12, and 11 is Stretched 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.