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 if0 < n < ary_size
- returns NULL if
n == 0
- returns a copy of the array
ary
ifn >= 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 toary_size
. - if
0 < n < ary_size
,res_size
must be set ton
.
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
Similar Kata:
Stats:
Created | Jun 25, 2017 |
Published | Jun 25, 2017 |
Warriors Trained | 590 |
Total Skips | 50 |
Total Code Submissions | 1078 |
Total Times Completed | 237 |
C Completions | 237 |
Total Stars | 12 |
% of votes with a positive feedback rating | 81% of 77 |
Total "Very Satisfied" Votes | 52 |
Total "Somewhat Satisfied" Votes | 21 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |