如何找到一个阶乘? [英] How to find a factorial?
本文介绍了如何找到一个阶乘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能写一个程序找到任何数量的阶乘?
How can I write a program to find the factorial of any number?
推荐答案
这将为阶乘工作正整数(虽然非常小的子集):
This will work for the factorial (although a very small subset) of positive integers:
unsigned long factorial(unsigned long f)
{
if ( f == 0 )
return 1;
return(f * factorial(f - 1));
}
printf("%i", factorial(5));
由于您的问题(和水平已承认)的性质,该解决方案是基于更解决这个,而不是将在接下来的置换引擎中使用的函数的概念
Due to the nature of your problem (and level that you have admitted), this solution is based more in the concept of solving this rather than a function that will be used in the next "Permutation Engine".
这篇关于如何找到一个阶乘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文