20201220蔡笃俊进制转换的学习
作者:互联网
娄老师给出的伪代码是英文= =,一开始绕晕我了,给大家翻译一一下,以免像我一样= =
newBase在这伪代码中的意思应该是新的进制数,decimalNumber是你要转换的数,quotient是短除法的商,remainder是余数。这样一来伪代码就很容易看懂了。
Write "Enter the new base"
Read newBase
Write "Enter the number to be converted"
Read decimalNumber
Set quotient to 1
WHILE (quotient is not zero)
Set quotient to decimalNumber DIV newBase
Set remainder to decimalNumber REM newBase
Make the remainder the next digit to the left in the answer
Set decimalNumber to quotient
Write "The answer is "
Write answer
经过宿舍内的讨论,我们认为这个伪代码是这样表示的:先输入要转换的进制数,再输入你要读取的数,然后利用短除法,将要转换的数除去进制数,将余数从右到左排列
代码实现如下:
测试:
结果正确,至此,完成。
标签:Set,进制,蔡笃俊,Write,decimalNumber,newBase,20201220,quotient 来源: https://www.cnblogs.com/acacacaac/p/13929772.html