Answer to Question #269155 in Visual Basic for mike

Question #269155

Write a method integerPower ( base, exponent ) that returns the value of ? base exponent


For example, integerPower (3,4) calculates 34( or 3∗3 in 3∗3).34( or 3∗3 in 3∗3). Assume that exponent is a positive, nonzero integer and that base is an integer. Method integerPower should use a for or while statement to control the calculation. Do not use any math library methods. Incorporate this method into an application that reads integer values for base and exponent and performs the calculation with the integerPower method.

1
Expert's answer
2021-11-20T12:36:47-0500
Imports System.IO


Module Module1
    Sub Main()
        Console.Write("Enter base: ")
        Dim base As Integer = Integer.Parse(Console.ReadLine())
        Console.Write("Enter exponent: ")
        Dim exponent As Integer = Integer.Parse(Console.ReadLine())
        Console.WriteLine("Power: {0}", integerPower(base, exponent))
        Console.ReadLine()
    End Sub
    Function integerPower(ByVal base As Integer, ByVal exponent As Integer)
        Dim power = 1
        For i As Integer = 1 To exponent
            power *= base
        Next
        Return power
    End Function


End Module

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS