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#include 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; }
For more C language and related programming tutorials, please pay attention toPHP 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!