Home  >  Article  >  Backend Development  >  Does C language allow recursive calling of functions?

Does C language allow recursive calling of functions?

angryTom
angryTomOriginal
2020-03-02 10:29:206505browse

Does C language allow recursive calling of functions?

Does the C language allow recursive calls of functions?

Yes. The process in which a function in C language directly or indirectly calls itself is called recursion.

1. Two necessary conditions for recursion

1. There are restrictions. When this condition is met, recursion will not Continue again.

2. Each recursive call gets closer and closer to this limit.

Recommended learning: c language video tutorial

2. Classic recursion question-finding the nth Fibonacci number

#include <stdio.h>
#include <stdlib.h>
int fibonacci(int n)
{
	if(n <= 2)
	{
		return 1;
	}
	else
	{
	    return fibonacci(n - 1) + fibonacci(n - 2);
    }
}
int main()
{
	int n;
	printf("请输入你想输出第几项的斐波那契数:\n");
	scanf("%d", &n);
	printf("%d\n", fibonacci(n));
	system("pause");
	return 0;
}

Does C language allow recursive calling of functions?

For more C language and related programming tutorials, please pay attention to PHP Chinese website!

The above is the detailed content of Does C language allow recursive calling of functions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn