Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use a for loop to sum the elements in the following vector: V = [10, 27, 66, 43,

ID: 2079477 • Letter: U

Question

Use a for loop to sum the elements in the following vector: V = [10, 27, 66, 43, 72, 87, 56, 98, 33, 23.5, 8.5, 77, 36, 2, 11, 85, 55, 63, 4, 39]. You will need to first determine the size of the vector. Check your answer with the sum function. Repeat the previous problem, this time using a while loop. Write a function called "isInt" to check whether an input number is an integer. The function should display a sentence of the form: "22.5 is not an integer!" or "99 is an integer!" if the inputs were respectively 22.5 and 99.

Explanation / Answer

clc

clear all

close all

V=[10 27 66 43 72 87 56 98 33 23.5 8.5 77 36 2 11 85 55 55 63 4 39];

[Row, Column]=size(V);

Y=0;

for i=1:length(V)

Y=Y+V(i) ;

end

SumV=sum(V);

if (Y-SumV==0)

fprintf(' Sum is correct ');

else

fprintf(' Sum is incorrect ');

end