For the last day in MarCh we'll have a special C based problem. The goal is to create a function that takes in an array and returns the x'th element in an array. The trick is that you should also support negative numbers. So looking for -1 should return the last element in the array. Looking for -10 in a 5 element array can return index out of bounds or an error of your choosing.
Comments:
David - 9 years, 8 months ago
Well, this accomplishes the task. Test main included. Note the unsafe ability to specify an incorrect length.
Didn't feel like refining this to involve proper error handling in some manner, so zero is reserved for incorrect input.
reply permalink