Supports C tail recursion

Recursion refers to the method of using the function itself when defining a function.

for example:
Once upon a time there was a mountain and a temple in the mountain. There was an old monk in the temple. He told the little monk a story! What is the story? “As soon as there was a mountain, there was a temple in the mountain, and there was an old monk in the temple telling a story to a young monk! What is the story? ”There used to be a mountain, a temple in the mountain, and an old monk in the temple. Tell the little monk a story! What is the story? ... '"

The syntax format is as follows:

Flow chart:

The C language supports recursion, ie a function can call itself. However, when using recursion, programmers must be careful to define a condition to exit the function. Otherwise it goes into an infinite loop.

Recursive functions play an important role in solving many math problems, such as: B. in calculating the factorial of a number, generating Fibonacci sequences, etc.

1. Factor of a number

The following example uses a recursive function to calculate the factorial of a specific number:

When the above code is compiled and executed, the following results are achieved:

2. Fibonacci sequence

The following example uses a recursive function to generate a Fibonacci sequence of a specific number:

When the above code is compiled and executed, the following results are achieved: