I am trying to replace a integer n if odd by 3 times value plus one or if even replace by half the value and count the steps but the counting does not seem to occur properly
이전 댓글 표시
n = input('input the number');
while(n~=1)
m=1;
if(n>1)
if(rem(n,2)==0)
n=n/2;
else
n=3*n+1;
end
end
m=m+1;
end
댓글 수: 1
Sachin Ganjare
2012년 10월 29일
Do format the code properly, so that it will be readable.
채택된 답변
추가 답변 (1개)
Sachin Ganjare
2012년 10월 29일
0 개 추천
m=1 should be outside the while loop.
Hope it helps!!
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!