For loop confused as to which value to consider
<p>I have this loop here:</p><pre><br /><code>while(n != 0)<br /> {<br /> ld = n % 10;<br /> System.out.println(ld);<br /><br /> for ( i=1; i <= ld; i++)<br /> {<br /> f = f * i;<br /> }<br /><br /> System.out.println(f);<br /><br /> n /= 10;<br /> }<br /></code><br /></pre><p>Let us consider a number, say <code>123</code>. Now, this loop calculates the factorial of <code>3</code> accurately, but when it restarts to calculate the factorial of <code>2</code>, the for loop gets confused as to which value to take for the variable <code>ld</code>. Is there any solution to this?</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34526013/for-loop-confused-as-to-which-value-to-consider">http://ift.tt/1QXwsQi</a></h2>
Nhận xét
Đăng nhận xét