Q:

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

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now