Task 1 Task 2 Task 3

Task 1

Given n of 1 or more, return the factorial of n, which is n * (n-1) * (n-2) ... 1. Compute the result recursively (without loops).

Here are some examples of results of a call to the function factorial:

factorial(1) → 1

factorial(2) → 2

factorial(3) → 6

Code the function recursively using a high-level programming language of your choice. The function header is:

FUNCTION factorial(n : INTEGER) RETURNS INTEGER

Task 2

We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.

Here are some sample results of several calls to the function:

triangle(0) → 0

triangle(1) → 1

triangle(2) → 3

Code the function recursively using a high-level programming language of your choice. The function header is:

FUNCTION triangle(n : INTEGER) RETURNS INTEGER

Task 3

Design a function to determine how many times a certain letter appears in the string.

Code the function recursively using a high-level programming lanuage of your choice.

The function header in pseudocode is written as:

FUNCTION countLetter(s : STRING, l : STRING) RETURNS INTEGER

where the parameter s is the string being searched and l is the letter being searched for.