This preview shows page 1. Sign up to view the full content.
CS100M Section Exercise 7
1
Examining a subarray
[From Lab Exercise 6] Write a function
vectorQuery(v,n,r)
to determine whether the number
r
appears in
the ±rst
n
cells of vector
v
. The function returns 1 if
r
is in the ±rst
n
cells of
v
and 0 otherwise. Your function
assumes that
v
is a vector of numbers,
n
is a positive integer, and
r
is a number. Use a loop to do the search.
Make sure that the loop index doesn’t go “out of bounds” (if
n
is greater than the length of vector
v
).
2
Concatenating arrays
[From Lab Exercise 6] Write a function
sequence(m)
that generates a sequence of random
integer
numbers
between 1 and
m
, inclusive, stopping when a value is repeated for the ±rst time. The function returns an array
containing all the numbers generated (in the order in which they were generated) except for the last value that
is a repeated occurrence.
Example: If the generated sequence is 3 1 9 5 7 2 5, the array to be returned should be 3 1 9 5 7 2.
Hints:
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '07
 FAN/VANLOAN

Click to edit the document details