Grade 13 Option C (Muckoon)
Grade 13 Option C (Muckoon)
14 JAN 2025
19.2 Recursion
END FUNCTION
ELSE
ENDIF
RETURN ProductORsum
END FUNCTION
ELSE
ENDIF
RETURN Area
END FUNCTION
4. Write a function TAX to calculate the tax based on the following table.
Otherwise it is 5% of salary
ELSE
ELSE
ENDIF
ENDIF
END FUNCTION
RECURSIVE FUNCTION
EXPLANATION
Example Factorial.
Factorial(0) =1
Factorial(1) =1
Factorial(2) = 1x2 = 2
Factorial(N) =N X F(N-1)
IF N = 0 OR N = 1 THEN
Base
Factorial = 1 Case
Factorial = N * Factorial(N-1)
Endif
END FUNCTION
SUB main()
F = Console.Readline()
Factorialof= Factorial(F)
Console.readkey()
End Sub
Example 2
FIBONACCI
M 1 2 3 4 5 6 7 8 M
Fibonacci (M) 1 1 2 3 5 8 13 21
Base Case:
Fibonacci = 1
General Case
Fibonacci = 1
Else
END FUNCTION
Example 3
Write a recursive procedure to output a specific message P number of times input by the user
Output will be
Nobin
Nobin
Nobin
Nobin
Nobin
IF P = 1 THEN
Console.Writeline(msg)
ELSE
Console.Writeline(msg)
ENDIF
End sub