Académique Documents
Professionnel Documents
Culture Documents
//Program 5
//This program will use recursion to raise
//a number to a power.
Module Main()
//Variables n and y hold values the users want to input
//While the answer variable holds the value from the function
//toThePower
Declare Integer n, y
Declare Integer answer
Display "Enter a base value"
Input n
Display "Enter a value for the exponent"
Input y
Set answer = toThePower(n, y)
Display "The answer of",n,"^",y,"is:",answer
End Main
//Function toThePower iterates y - 1 to get the next power
//the base variable needs to complete the problem.
Function toThePower(Integer n, y)
If y == 1 Then
Return n
Else
If y == 0 Then
Return 1
Else
If y > 1 Then
Return n * toThePower(n, y - 1)
End If
End Function toThePower
3*3,2
9
9*3,1
27,1
3^3
3*3*3