6 kyu

Arrays, take n elements

Description:

Write ary_take function, that takes an array ary, ary_size - the size of the array, value n - the number of first elements to take, and a pointer to an unsigned integer res_size, and does the following:

  • returns a subarray with n elements if 0 < n < ary_size
  • returns NULL if n == 0
  • returns a copy of the array ary if n >= ary_size

In all cases res_size must be set to the size of the resulting subarray.

  • if n == 0, res_size must also be set to 0.
  • if n >= ary_size, res_size must be set to ary_size.
  • if 0 < n < ary_size, res_size must be set to n.

Examples:

For array { 0, 1, 1, 2, 3, 5 } and n = 3, return { 0, 1, 1 } and set res_size to 3.

For array { 9, 8, 7, 6, 5, 4 } and n = 0, return NULL and set res_size to 0.

For array { 1, 2, 4, 8, 16, 32 } and n = 255 return the copy of the array and set res_size to its size, in this case it's 6.

Arrays
Algorithms

Stats:

CreatedJun 25, 2017
PublishedJun 25, 2017
Warriors Trained590
Total Skips50
Total Code Submissions1078
Total Times Completed237
C Completions237
Total Stars12
% of votes with a positive feedback rating81% of 77
Total "Very Satisfied" Votes52
Total "Somewhat Satisfied" Votes21
Total "Not Satisfied" Votes4
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • lilsweetcaligula Avatar
  • smile67 Avatar
  • FArekkusu Avatar
Ad