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.

Expert's answer

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
LATEST TUTORIALS
APPROVED BY CLIENTS