Write a function prodby2 that will receive a value of a positive integer n and will calculate and return the product of the odd integers from 1 to n (or from 1 to n-1 if n is even). Use a for loop
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:5| Question number:6.5
All Answers
total answers (1)
prodby2.m
function out = prodby2(n)
% Calculates and returns 1*3*5*..*n
% Format of call: prodby2(n)
% Returns product from 1 to n in steps of 2
out = 1;
for i = 1:2:n
out = out * i;
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer