The counter in a for or while loop can have an explicit increment: for i=m:k:n. This advances the counter i by increment k each time. In this problem we will evaluate the product of the first 9 even numbers 2·4·6·...·18 in two ways: (a) Write a script file that evaluates the product of the first 9 even numbers using a for loop.(b) Evaluate the product of the first 9 even numbers using a single MATLAB command. Use the MATLAB command prod.

Respuesta :

Answer:

(b) prod(2:2:18)

Explanation:

(a) Evaluate the product of the first 9 even numbers:

answer = 1;

for even = 2:2:18

    answer = answer*even;

disp(answer)

(b) Evaluate the product of the first 9 even numbers using MATLAB prod() function

answer = prod(2:2:18)

disp(answer)