In this lesson, we’ll look at some functions and decide on their prototypes. We’ll be looking at what should be the inputs and outputs of these functions, without discussing the internal details (that we will discuss in the upcoming lessons).

Some examples of designing functions

Let’s look at some example functions and their respective prototypes.

Factorial computation

Factorial is a mathematical quantity that measures the number of possible ordered arrangements. This is shown below:

n!=n×(n1)×(n2)×...×2×1n! = n \times (n-1) \times (n-2) \times ... \times 2 \times 1

For example, the factorial of 5 is calculated as 5×4×3×2×1=1205 \times 4 \times 3 \times 2 \times 1 = 120.

From this definition, we can see that both the input and output of this function should be integers because, when we multiply integers, we get an integer. The image of the factorial function as a black box (without focusing on the actual code implementation of the function) can be seen below.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy