필터 지우기
필터 지우기

how to get out infinite loop

조회 수: 1 (최근 30일)
OLUBUKOLA ogunsola
OLUBUKOLA ogunsola 2016년 6월 24일
댓글: jgg 2016년 6월 24일
this code required to calculate the smallest multiple with uint64 format bit gets stuck on argument 45. it only displays busy . can someone explain why?
function answer = smallest_multiple (N)
limit =1e15;
for i = N:N:limit
for j = N:-1:1
if mod(i,j) ~= 0
break
end
end
if j == 1
answer =uint64(i);
break
end
end
  댓글 수: 3
OLUBUKOLA ogunsola
OLUBUKOLA ogunsola 2016년 6월 24일
anything smaller than that comes back with the result ' output argument "answer" ( and maybe others) not assigned during call to "smallest_multiple" . but it doesn't do that with output argument up to 30. then it gives the error
jgg
jgg 2016년 6월 24일
You break out of your loop if i is not divisible by j at any point; this means answer is not assigned in many loop iterations. This is probably not what you want to do here.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by