Exponentiation with infix operators in (or operating on) the base: Difference between revisions

Content added Content deleted
(→‎{{header|Lua}}: added Lua solution)
(added AWK)
Line 159: Line 159:
x = 5 p = 2 -x**p 25 -(x)**p 25 (-x)**p 25 -(x**p) -25
x = 5 p = 2 -x**p 25 -(x)**p 25 (-x)**p 25 -(x**p) -25
x = 5 p = 3 -x**p -125 -(x)**p -125 (-x)**p -125 -(x**p) -125
x = 5 p = 3 -x**p -125 -(x)**p -125 (-x)**p -125 -(x**p) -125
</pre>
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f EXPONENTIATION_WITH_INFIX_OPERATORS_IN_OR_OPERATING_ON_THE_BASE.AWK
# converted from FreeBASIC
BEGIN {
print(" x p | -x^p -(x)^p (-x)^p -(x^p)")
print("--------+------------------------------------")
for (x=-5; x<=5; x+=10) {
for (p=2; p<=3; p++) {
printf("%3d %3d | %8d %8d %8d %8d\n",x,p,(-x^p),(-(x)^p),((-x)^p),(-(x^p)))
}
}
exit(0)
}
</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>
</pre>