I need help with this matlab assignment. It is running forever and not printing
ID: 3906079 • Letter: I
Question
I need help with this matlab assignment. It is running forever and not printing an answer. The code in the picture is supposed to be debugged.
I know that cnt+1 needs to change to cnt=cnt+1 I don’t think the ‘s’ is needed for the input I think it should be mod(M,10) I think it should be M=floor(M/10);
Above are the corrections I think should happen, and I have already tried, but I am missing something. Please help! % Lowest multiple with 93 and 03 clc: clear: 3-N input ('Enter a positive whole number N: , 's) 4- "cnt = 1; 5- while true 7-? MN*cnt; while M >= 1 remainder -mod (10, M); if remainder9 1I remainder 0 10 - continue: else floor (M+10) ; 12- 13 - M = end end if MK 1 15 break; 17 18 19? 20- end cnt+i: end fprint f("Lowebt t multiple with only 9a and 0s: sdn,N) Command Window Enter a positive whole number N: s 2 continue: ?>> fxi
Explanation / Answer
Matlab Code:
clc; clear;
N = input('Enter a positive whole number N: ');
cnt = 1;
flag = true;
while flag
M = N*cnt;
while M > 0
reminder = mod(M, 10);
if reminder ~= 9 && reminder ~= 0
flag = false;
break
end
M = floor(M/10);
end
if flag == false
flag = true;
cnt = cnt + 1;
else
break
end
end
fprintf('Lowest multiple with only 9s and 0s: %d ', N*cnt);