MATLAB: Write a function count_odd that takes two arguments: low_bound and high_bound. The function counts how many odd values are there between the low_bound and the high_bound. Last it returns the number of odd numbers between these two values.

count_odd

Here is what I have. All help is appreciated.
function count_odd(low_bound, high_bound)
% promt user to enter low_bound and high_bound
low_bound=input('Enter low bound: ')
high_bound=input('Enter high bound: ')
end

Best Answer

l=1 %lower bound
u = 9 %upper bound
boundary_vector=l:u
counter = 0;
for i = 1:length(boundary_vector)
if rem(boundary_vector(i),2)==0
counter = counter + 1;
end
end
odds = length(boundary_vector) - counter
Related Question