递归函数

#include<stdio.h>

int main(void)
{
 unsigned int j;
 unsigned long int factorial(unsigned int n);
 for(j=0;j<11;j++)
 {
  printf("%2u!=%lu\n",j,factorial(j));
 }
  return 0;
}

unsigned long int factorial(unsigned int n)
{
  unsigned int result;
 if(n==0)
  {
   result=1;
  }
 else
 {
   result=n*factorial(n-1);
 }
 return result;
}
运行结果:
递归函数_第1张图片

你可能感兴趣的:(递归函数)