Write a function that adds all the even numbers between 2 an

Write a function that adds all the even numbers between 2 and 3^n, where n is a number passed to the faunction.

Solution

function y=sumnalleven(n)
y=0;
for i=2:3^n
if rem(i,2)==0
y=y+i;
end
end

RESULT:

>> sumnalleven(2)

ans =

20

>> sumnalleven(5)

ans =

14762

 Write a function that adds all the even numbers between 2 and 3^n, where n is a number passed to the faunction. Solutionfunction y=sumnalleven(n) y=0; for i=2:

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site