📜  C语言中的递归函数代码示例

📅  最后修改于: 2022-03-11 15:04:38.690000             🧑  作者: Mango

代码示例1
/*
Program: Factorial of a given number using recursive function.
Author: Codesansar
Date: Jan 22, 2018
*/
#include
#include

int fact(int n); /* Function Definition */

void main()
{
 int num, res;
 clrscr();
 printf("Enter positive integer: ");
 scanf("%d",&num);
 res = fact(num); /* Normal Function Call */
 printf("%d! = %d" ,num ,res);
 getch();
}
int fact(int n) /* Function Definition */
{
 int f=1;
 if(n <= 0)
 {
  return(1);
 }
 else
 {
  f = n * fact(n-1); /* Recursive Function Call as fact() calls itself */
  return(f);
 }
}