How to resolve the algorithm Exponentiation operator step by step in the VBScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Exponentiation operator step by step in the VBScript 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 VBScript programming language
Source code in the vbscript programming language
Function pow(x,y)
pow = 1
If y < 0 Then
For i = 1 To Abs(y)
pow = pow * (1/x)
Next
Else
For i = 1 To y
pow = pow * x
Next
End If
End Function
WScript.StdOut.Write "2 ^ 0 = " & pow(2,0)
WScript.StdOut.WriteLine
WScript.StdOut.Write "7 ^ 6 = " & pow(7,6)
WScript.StdOut.WriteLine
WScript.StdOut.Write "3.14159265359 ^ 9 = " & pow(3.14159265359,9)
WScript.StdOut.WriteLine
WScript.StdOut.Write "4 ^ -6 = " & pow(4,-6)
WScript.StdOut.WriteLine
WScript.StdOut.Write "-3 ^ 5 = " & pow(-3,5)
WScript.StdOut.WriteLine
You may also check:How to resolve the algorithm Arithmetic-geometric mean step by step in the Prolog programming language
You may also check:How to resolve the algorithm McNuggets problem step by step in the Wren programming language
You may also check:How to resolve the algorithm Closest-pair problem step by step in the PL/I programming language
You may also check:How to resolve the algorithm Rosetta Code/Count examples step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Descending primes step by step in the XPL0 programming language