📄 longdiv.prg
字号:
* longdiv.prg
* 长除法
parameters a,b
private except eachlen,alllen
* 处理左边的0
l0=len(a)
not0=0
for t=1 to l0
if substr(a,t,1)="0"
not0=not0+1
else
exit
endif
next t
a=substr(a,not0+1,l0-not0)
b=substr(b,not0+1,l0-not0)
*eachlen=10
*alllen=len(a)
*s0=replicate("0",alllen)
longdivc="" && 商
longdivi=0 && 除数移位计数
c0=0 && 部分商
@ 7,10 say "longdiv除数已回缩到第 位"
do while .t.
@ 7,31 say str(longdivi)
if a>=b
a=longsub(a,b)
c0=c0+1
else
longdivc=longdivc+str(c0,1) && 搜集商
longdivi=longdivi+1
l=right(b,1) &&最后一位四舍五入
if l>"4"
l2=str(val(substr(b,alllen-1,1))+1,1)
b="0"+left(b,alllen-2)+l2
else
b="0"+left(b,alllen-1) &&除数右移1位
endif
c0=0
endif
if longdivi>=alllen &&.or.a=s0.or.b=s0
exit
endif
enddo
a=len(longdivc)
if a<alllen
longdivc=longdivc+replicate("0",alllen-a)
endif
return longdivc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -