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

I just found out i\'m not allowed to use the sum() function for this homework an

ID: 3554608 • Letter: I

Question

I just found out i'm not allowed to use the sum() function for this homework and its almost due so i really need help. we are supposed to demonstrate looping, so no vectorization isn't being permitted:

Below is what i have, please change it so that it doesn't use sum or vectorization.

the prog is receiving a row array of numbers as input, determines which are divisible by 9, and then creates and treturns a row array w/ locical values as output: 1 if numb is divis by 9, and 0 if it is not. BUT has to be done without using division...

function [X] = isdiv9(Input)

if size(Input,1) > 1

error('Input must be a scalar or in a row array')

elseif(max(Input)>1*10^10)

error('All numbers in the input array must be less than 1 x 10^10');

elseif any(~mod(Input,1)==0)

error('All numbers in the input array must be integers')

end

for i=1:numel(Input)

a = abs(Input(i));

while a > 9

sum(i)=0;

a = num2str(a);

for j = 1:numel(a)

sum(i) = sum(i) + str2num(a(j));

end

a = sum(i);

end

if a==0 || a==9

X(i) = 1;

else X(i) = 0;

end

end

Explanation / Answer

This function already follows all of your requirements!! nothing to be changed