阶乘在c语言中怎么表示

如题所述

方法如下:

/*This program can calculate the factorial of (int n).*/

#include <stdio.h>

int factorial(int n)

{

return (n == 1)?n:factorial(n-1)*n;//recursion.

}

int main(void)

{

int n,fac;

printf("Please input the value of n:");//initialize n.

scanf("%d",&n);

fac = factorial(n)//variable fac is not necessary.

printf("The result is:%d\n",fac);        

return 0;

}

相关内容:

阶乘是定义在自然数范围里的(大多科学计算器只能计算 0~69 的阶乘),小数科学计算器没有阶乘功能,如 0.5!,0.65!,0.777!都是错误的。但是,有时候我们会将Gamma 函数定义为非整数的阶乘,因为当 x 是正整数 n 的时候,Gamma 函数的值是 n-1 的阶乘。

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网