Please help me solve this Not sure whats the question mean I

Please help me solve this. Not sure what\'s the question mean. I have write my algorithm for this but not sure it is right or not.

Input: A positive integer n, a sequence s: a1, a2 ... an of n numbers and a number k.

Output: \"term\" i \"is within 1 of\" k or \"no term in sequence is within 1 of\" k

1. i := 1 [i assigned as 1]

2. while i <= n do

begin

3. if ai < k, then output \"i terms in s is within 1 of k\"

  

if ai > k, then output \"i terms in s is NOT within 1 of k\"

  i:= i + 1 [accumulate i to exit while loops ]

end

I\'m confuse of what\'s the mean of within 1 of k? My interpretation is the numbers in i terms of sequence s which is less than k.

Please help me with this question. Thank you so much!

Solution

this question simply means you have to find an algorithm to check whether a series denoted by s (contanining a1,a2,............an terms ) does lie in the range of 1 to k. if any of the term does lie in the range then return true else return false.

Please help me solve this. Not sure what\'s the question mean. I have write my algorithm for this but not sure it is right or not. Input: A positive integer n,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site