C递归计算阶乘的两种写法(1)

This is used to calculate this function

#include 
long long factoiral(int n)
{
	int i = 1;
	for (int m = 1; m <= n; m++)
		m *= i
	return m;
}
long long C(int n, int m)
{
	return (factorial(n) / (factorial(m) * factorial(n - m))
}

C递归计算阶乘的两种写法(1)_第1张图片

#include 
long long factorial(int n)
{
  if (n == 1)
    return 1;
else
    return n * factorial(n - 1);
}

long long yoo(int n, int m)
{
	return factorial(n) / factorial(m) * factorial(n - m);
}


int main(void)
{
    long long answer;
   printf("this is once test\n");
   answer = factorial(10);
   printf("answer = %lld", answer);
}

结果如下(The result would be):C递归计算阶乘的两种写法(1)_第2张图片
在一定程度上,这两种方法是可行,但会出现上溢现象,如何解决将留到下次再讲

你可能感兴趣的:(My,10,Grade,Studying,Note)