Exponentiation with infix operators in (or operating on) the base: Difference between revisions
Exponentiation with infix operators in (or operating on) the base (view source)
Revision as of 00:53, 18 June 2022
, 1 year agoExponentiation with infix operators in (or operating on) the base in various BASIC dialents (BASIC256, Gambas, QBasic, Run BASIC, True BASIC, PureBasic, XBasic and Yabasic)
(add →Pascal) |
(Exponentiation with infix operators in (or operating on) the base in various BASIC dialents (BASIC256, Gambas, QBasic, Run BASIC, True BASIC, PureBasic, XBasic and Yabasic)) |
||
Line 185:
5 3 | -125 -125 -125 -125
</pre>
=={{header|BASIC}}==
==={{header|BASIC256}}===
<lang BASIC256>print " x p | -x^p -(x)^p (-x)^p -(x^p)"
print ("-"*15); "+"; ("-"*45)
for x = -5 to 5 step 10
for p = 2 to 3
print " "; rjust(x,2); " "; ljust(p,2); " | "; rjust((-x^p),6); " "; rjust((-(x)^p),6); (" "*6); rjust(((-x)^p),6); " "; rjust((-(x^p)),6)
next p
next x</lang>
{{out}}
<pre> x p | -x^p -(x)^p (-x)^p -(x^p)
---------------+---------------------------------------------
-5 2 | -25.0 -25.0 25.0 -25.0
-5 3 | 125.0 125.0 125.0 125.0
5 2 | -25.0 -25.0 25.0 -25.0
5 3 | -125.0 -125.0 -125.0 -125.0</pre>
==={{header|Gambas}}===
<lang gambas>Public Sub Main()
Print " x p | -x^p -(x)^p (-x)^p -(x^p)"
Print "----------------+---------------------------------------------"
For x As Integer = -5 To 5 Step 10
For p As Integer = 2 To 3
Print " "; Format$(x, "-#"); " "; Format$(p, "-#"); " | "; Format$((-x ^ p), "-###"); " "; Format$((-(x) ^ p), "-###"); " "; Format$(((-x) ^ p), "-###"); " "; Format$((-(x ^ p)), "-###")
Next
Next
End</lang>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{works with|FreeBASIC}}
<lang qbasic>PRINT " x p | -x^p -(x)^p (-x)^p -(x^p)"
PRINT "----------------+---------------------------------------------"
FOR x = -5 TO 5 STEP 10
FOR p = 2 TO 3
PRINT USING " ## ## | #### #### #### ####"; x; p; (-x ^ p); (-(x) ^ p); ((-x) ^ p); (-(x ^ p))
NEXT p
NEXT x</lang>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
{{works with|QBasic}}
{{works with|True BASIC}}
<lang lb>print " x"; chr$(9); " p"; chr$(9); " | "; chr$(9); "-x^p"; chr$(9); " "; chr$(9); "-(x)^p"; chr$(9); " "; chr$(9); "(-x)^p"; chr$(9); " "; chr$(9); "-(x^p)"
print "----------------------------+-----------------------------------------------------------------"
for x = -5 to 5 step 10
for p = 2 to 3
print " "; x; chr$(9); " "; chr$(9); p; chr$(9); " | "; chr$(9); (-1*x^p); chr$(9); " "; chr$(9); (-1*(x)^p); chr$(9); " "; chr$(9); ((-1*x)^p); chr$(9); " "; chr$(9); (-1*(x^p))
next p
next x
end</lang>
{{out}}
<pre>Similar to FreeBASIC entry.</pre>
==={{header|True BASIC}}===
<lang qbasic>PRINT " x p | -x^p -(x)^p (-x)^p -(x^p)"
PRINT "----------------+---------------------------------------------"
FOR x = -5 TO 5 STEP 10
FOR p = 2 TO 3
PRINT USING " ## ## | #### #### #### ####": x, p, (-x^p), (-(x)^p), ((-x)^p), (-(x^p))
NEXT p
NEXT x
END</lang>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|PureBasic}}===
<lang PureBasic>OpenConsole()
PrintN(" x p | -x^p -(x)^p (-x)^p -(x^p)")
PrintN("----------------+---------------------------------------")
For x.i = -5 To 5 Step 10
For p.i = 2 To 3
PrintN(" " + Str(x) + " " + Str(p) + " | " + StrD(Pow(-x,p),0) + #TAB$ + StrD(Pow(-1*(x),p),0) + #TAB$ + StrD(Pow((-x),p),0) + #TAB$ + " " + StrD(-1*Pow(x,p),0))
Next p
Next x
Input()
CloseConsole()</lang>
{{out}}
<pre> x p | -x^p -(x)^p (-x)^p -(x^p)
----------------+---------------------------------------
-5 2 | 25 25 25 -25
-5 3 | 125 125 125 125
5 2 | 25 25 25 -25
5 3 | -125 -125 -125 -125</pre>
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<lang xbasic>PROGRAM "Exponentiation with infix operators in (or operating on) the base"
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
PRINT " x p | -x**p -(x)**p (-x)**p -(x**p)"
PRINT "----------------+-----------------------------------------------"
FOR x = -5 TO 5 STEP 10
FOR p = 2 TO 3
PRINT " "; FORMAT$("##",x); " "; FORMAT$("##",p); " | "; FORMAT$("######",(-x**p)); " "; FORMAT$("######",(-(x)**p)); " "; FORMAT$("######",((-x)**p)); " "; FORMAT$("######",(-(x**p)))
NEXT p
NEXT x
END FUNCTION
END PROGRAM</lang>
{{out}}
<pre>Similar to FreeBASIC entry.</pre>
==={{header|Yabasic}}===
<lang yabasic>print " x p | -x^p -(x)^p (-x)^p -(x^p)"
print "----------------+---------------------------------------------"
for x = -5 to 5 step 10
for p = 2 to 3
print " ", x using "##", " ", p using "##", " | ", (-x^p) using "####", " ", (-(x)^p) using "####", " ", ((-x)^p) using "####", " ", (-(x^p)) using "####"
next p
next x</lang>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
=={{header|F_Sharp|F#}}==
|