2 回答

TA貢獻(xiàn)1868條經(jīng)驗(yàn) 獲得超4個(gè)贊
這是解決方案:
HTML:
<div class="column1">
? ? <div class="input">
? ? ? <button onclick="problem_09()"> Run the program </button>
? ? </div>
? ? <strong><div id="output"> </div></strong>
? </div>
記者:
function problem_09() {
? var outputObj = document.getElementById("output");
? var a = parseInt(prompt("Please enter a number: ", ""));
? var digit = "";
? outputObj.innerHTML = ""
? while(a > 0){
? ? let num = a%10
? ? a = Math.floor(a/10)
? ? digit += "<p>"+num+"</p>"
? }
? outputObj.innerHTML = digit + "<br><br>" + "program ended";
? document.getElementsByTagName("button")[0].setAttribute("disabled","true");
}

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊
從數(shù)學(xué)上講,取余數(shù)模 10 除以 10。在簡(jiǎn)單的代碼中,
num = some number
while (num>0):
print(num%10)
num = num/10
添加回答
舉報(bào)