In this video, we will translate the algorithm

we developed in the previous video into code.

We've included our algorithm as comments,

shown in blue, and we will turn these steps into C code.

To begin with, we are going to put all of the steps inside of a function factorial.

Factorial takes an integer in and returns an integer that is

the factorial of n. Now to determine if n is less than or equal to 0,

we're going to use an if/else statement.

If n is less than or equal to 0,

we want to answer 1 which we can do with a return statement.

Now, we want to represent the otherwise case

which is the else part of the if/else statement.

To do this more complicated case,

we need to create a new variable n_minus1_fact,

and we're going to have to make a function call to perform

a complex step and figure out what value to assign to n_minus1_fact.

The function we want to call happens to be the one we are writing.

So we place a call to factorial with the value n_minus1.

Now that we have the value n_minus1_fact,

we want to multiply it by n. That is the result

we'd like to return which we can do with a return statement.

Now, we've completed our function and our remaining steps would be to test and debug it.