编写函数fun,计算n!

Posted jun俊

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编写函数fun,计算n!相关的知识,希望对你有一定的参考价值。

#include <stdio.h>

double fun ( int n )
{ double result = 1.0 ;
/************found************/
if (n==0)
return 1.0 ;
while( n >1 && n < 170 )
/************found************/
result *= n--;
return result ;
}

main ( )
{ int n ;
printf("Input N:") ;
scanf("%d", &n) ;
printf("\n\n%d! =%lf\n\n", n, fun(n)) ;
}

根据阶乘的概念,从n开始,n!=n*(n-1)!,所以应该为result *=n--

以上是关于编写函数fun,计算n!的主要内容,如果未能解决你的问题,请参考以下文章