Jump to content

Modular inverse: Difference between revisions

Modular inverse in Chipmunk Basic, QBasic and True BASIC
(Modular inverse in Chipmunk Basic, QBasic and True BASIC)
Line 581:
{{out}}
<pre>1969</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{works with|QBasic}}
{{trans|BASIC256}}
<syntaxhighlight lang="qbasic">10 CLS
20 CALL modularinverse(42, 2017)
30 CALL modularinverse(40, 1)
40 END
50 SUB modularinverse(e,t)
60 d = 0
70 IF e < t THEN
80 b = e
90 c = 1
100 WHILE b > 1
110 s = INT(((t-b)/e)+1)
120 b = b+s*e
130 c = c+s
140 b = b-t
150 WEND
160 d = c
170 ENDIF
180 m = d
190 PRINT m
200 END SUB</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
Line 608 ⟶ 633:
610 RETURN
</syntaxhighlight>
 
==={{header|QBasic}}===
The [[#Chipmunk_Basic|Chipmunk Basic]] solution works without any changes.
<syntaxhighlight lang="qbasic"></syntaxhighlight>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">SUB modularinverse(e,t)
LET d = 0
IF e < t then
LET b = e
LET c = 1
DO WHILE b > 1
LET s = int(((t-b)/e)+1)
LET b = b+s*e
LET c = c+s
LET b = b-t
LOOP
LET d = c
END IF
LET m = d
PRINT m
END SUB
 
CALL modularinverse(42,2017)
CALL modularinverse(40,1)
END</syntaxhighlight>
 
=={{header|Batch File}}==
2,143

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.