Egyptian division: Difference between revisions

Egyptian division in PureBasic
(Added BASIC256, QBasic, True BASIC and Yabasic. Grouping BASIC dialects)
(Egyptian division in PureBasic)
Line 776:
{{out}}
<pre>580 divided by 34 using Egytian division returns 17 mod(ulus) 2</pre>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="PureBasic">OpenConsole()
Dim table.i(32, 2)
dividend.i = 580
divisor.i = 34
 
i.i = 1
table(i, 1) = 1
table(i, 2) = divisor
 
While table(i, 2) < dividend
i + 1
table(i, 1) = table(i -1, 1) * 2
table(i, 2) = table(i -1, 2) * 2
Wend
i - 1
answer = table(i, 1)
accumulator = table(i, 2)
 
While i > 1
i - 1
If table(i, 2)+ accumulator <= dividend:
answer = answer + table(i, 1)
accumulator = accumulator + table(i, 2)
EndIf
Wend
 
Print(Str(dividend) + " divided by " + Str(divisor) + " using Egytian division")
PrintN(" returns " + Str(answer) + " mod(ulus) " + Str(dividend-accumulator))
Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|QBasic}}===
2,130

edits