How to resolve the algorithm Exponentiation operator step by step in the ERRE programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Exponentiation operator step by step in the ERRE programming language
Table of Contents
Problem Statement
Most programming languages have a built-in implementation of exponentiation.
Re-implement integer exponentiation for both intint and floatint as both a procedure, and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an overloaded form should be provided for both intint and floatint variants.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Exponentiation operator step by step in the ERRE programming language
Source code in the erre programming language
PROGRAM POWER
PROCEDURE POWER(A,B->POW) ! this routine handles only *INTEGER* powers
LOCAL FLAG%
IF B<0 THEN B=-B FLAG%=TRUE
POW=1
FOR X=1 TO B DO
POW=POW*A
END FOR
IF FLAG% THEN POW=1/POW
END PROCEDURE
BEGIN
POWER(11,-2->POW) PRINT(POW)
POWER(π,3->POW) PRINT(POW)
END PROGRAM
You may also check:How to resolve the algorithm Look-and-say sequence step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Scope/Function names and labels step by step in the Phix programming language
You may also check:How to resolve the algorithm Operator precedence step by step in the Quackery programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Dyalect programming language
You may also check:How to resolve the algorithm Hello world/Line printer step by step in the Commodore BASIC programming language