For given following 5 times 5 matrix could you count and sto

For given following 5 times 5 matrix, could you count and store \'the numbers which are divisible by 3\' and \'the numbers which are divisible by 5\' separately by \'using while loop\', sum \'the numbers which are divisible by 3\' and \'the numbers which are divisible by 5\' without a repetition (i.e. one number which is divisible by \'3\' and \'5\' at the same time shouldn\'t be taken into account two times) by \'only using built-in \'sum(...)\' function\'? Respective 5 times 5 matrix: 1 2 5 8 9 15 25 30 17 19 65 60 70 80 90 12 13 18 28 22 17 18 87 98 99

Solution

count3=0

count5=0

M=[1 2 5 8 9;15 25 30 17 19;65 60 70 80 90;12 13 18 28 22;17 18 87 98 99]

i=0

j=0

sum=0

while(i<5)

while(j<5)

if(M[i][j]%3==0)

sum=sum+M[i][j]

count3++;

disp(\"%d\ \",M[i][j])

elseif(M[i][j]%5==0)

sum=sum+M[i][j]

count5++;

disp(\"%d\ \",M[i][j])

end

j++

end

i++

end

 For given following 5 times 5 matrix, could you count and store \'the numbers which are divisible by 3\' and \'the numbers which are divisible by 5\' separatel

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site