COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Recursion Factorial Program Fibonacci Program Integer Power Program Tower of Hanoi Program Max Element Program Palindrome Program Reverse String Program Array Sum Program



IntPower Program


Description

This program inputs two integers: base and exponent, and then calculates baseexponent using recursion technique.

Associated Concepts:

Recursion

Algorithm:

main method:

Declare variables

Input two integers: base and exponent from the keyboard

Call the recursive method myPow() with base and exponent as the arguments

Print the result

myPow method definition:

If the method is call with the base case: exponent is 0, it returns the result.

Otherwise, the method returns base * myPow(base, exponent - 1).

Source Code



Sample Run



Video