当前位置: 首页>>代码示例>>C++>>正文


C++ Factorial函数代码示例

本文整理汇总了C++中Factorial函数的典型用法代码示例。如果您正苦于以下问题:C++ Factorial函数的具体用法?C++ Factorial怎么用?C++ Factorial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Factorial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fastPermuteVectorOneLength

const VecStr fastPermuteVectorOneLength(std::string vec) {
  VecStr ans;
  int numOfPermutes = Factorial((int)vec.size());
  ans.reserve(numOfPermutes);
  do {
    ans.push_back(vec);
  } while (std::next_permutation(vec.begin(), vec.end()));
  return ans;
}
开发者ID:bailey-lab,项目名称:bibseq,代码行数:9,代码来源:vectorUtils.cpp

示例2: main

int main() {
    for (int i = 1; i <= 10; ++i)
        std::cout << i << "!=" << Factorial(i) << std::endl;
    /*std::cout << "Enter number: ";
    std::cin >> n;
    std::cout << "Result is ";
    std::cout << Factorial(n) << std::endl;*/
    return 0;
}
开发者ID:IvanSmirnovRus,项目名称:code,代码行数:9,代码来源:02.cpp

示例3: Factorial

void Factorial(long n)
{
  if (n == 0) {
    res = 1;
  } else {
    Factorial(n-1);
    res = n * res;
  }
}
开发者ID:rdspring1,项目名称:cs380c_pre_a4,代码行数:9,代码来源:hanoifibfac.c

示例4: Factorial

// Alright this is it --
// Let's think about the "definition" of factorial for a second.
// We said 3! = 1 * 2 * 3, which is equivalent to 3 * 2!.  We know 1! = 1, so by using
// those simple facts we design our "factorial function" to mimic these properties.
uint Factorial(uint num)
{
    // Factorial of one is one, thus we'll return one
    if(num == 1)
        return 1;

    else
        return num * Factorial(num - 1); // Otherwise it's num * the factorial of (num - 1)
}
开发者ID:jiangguang5201314,项目名称:ZNginx,代码行数:13,代码来源:main.c

示例5: msin

double msin(double x,double e) {
  double j,a,b,k;
  b= x ; j = 1 ;
  	do 	{
  		k = power(-1,j);  a  =k*power(x,2*j+1)/Factorial(2*j+1);	b =b + a;
		j+=1;
		}
	while(a*k>e);
return b;
}
开发者ID:samhvw8,项目名称:cprogramingIntroduction,代码行数:10,代码来源:casio.c

示例6: mex

double mex(double x,double e){
 	double j,a,b;
	b= 1; j = 1 ;
 	do 	{
 		a =power(x,j)/Factorial(j);b = b + a;
		j+=1;
		}
	while(a>e);
return b;
}
开发者ID:samhvw8,项目名称:cprogramingIntroduction,代码行数:10,代码来源:casio.c

示例7: TestFactorial

bool 
TestFactorial( )
{
    bool ok = true;
    cout << "Testing Factorial" << endl;

    TESTCHECK( Factorial( 12 ), 479001600, &ok );
    TESTCHECK( Factorial( 20LL ), 2432902008176640000LL, &ok );
    TESTCHECK( Factorial( 20. ), 2432902008176640000., &ok );
    TESTCHECKF( Factorial( 50. ), 3.0414093203509456e64, &ok );
    TESTCHECKFE( Factorial( 100. ), 9.3326e157, &ok, 1.e-5 );
    TESTCHECK( BinomialCoefficient( 19, 7 ), 50388., &ok );
    TESTCHECK( BinomialCoefficient( 20, 10 ), 184756., &ok );

    if ( ok )
        cout << "Factorial PASSED." << endl << endl;
    else
        cout << "Factorial FAILED." << endl << endl;
    return ok;
}
开发者ID:davidand36,项目名称:libEpsilonDelta,代码行数:20,代码来源:Factorial.cpp

示例8: Factorial

/** Computes a factorial. */
static INT Factorial(INT A)
{
	if(A == 0)
	{
		return 1;
	}
	else
	{
		return A * Factorial(A - 1);
	}
}
开发者ID:LiuKeHua,项目名称:colorful-engine,代码行数:12,代码来源:SHMath.cpp

示例9: Factorial

/** Computes a factorial. */
static int32 Factorial(int32 A)
{
	if(A == 0)
	{
		return 1;
	}
	else
	{
		return A * Factorial(A - 1);
	}
}
开发者ID:amyvmiwei,项目名称:UnrealEngine4,代码行数:12,代码来源:SHMath.cpp

示例10: p

	Polynom Polynom::TimeShift(double shift) const
	{
		vector<double> v;
		Polynom p(*this);
		for (int i = 0; i <= Power(); ++i)
		{
			v.push_back(p(shift) / double(Factorial(i)));
			p = p.Differenciate();
		}
		return Polynom(v);
	}
开发者ID:aaalex88,项目名称:ACorePoly,代码行数:11,代码来源:Polynom.cpp

示例11: Partition

void
/* Partition(int N, double Rtheta, double IJ[N*2]) */
Partition(int N, double Rtheta, double IJ[])
{
	int	level, var;
	/*	double	I[STRLEN], J[STRLEN], factor, sum;*/
        double	factor, sum;

	for (var = 1; var <= N; var++)
	{
	    sum = 0.0;

	    /* first term in hierarchy, occurs (N-1)! times */
	    level = 1;
	    sum += (Factorial(N - 1) * (d[level].m[var].X - Rtheta));
	    /* last term in hierarchy, also occurs (N-1)! times */
	    level = N;
	    sum += (Factorial(N - 1) * ReturnDiff(level, var));

	    for (level = 2; level < N; level++)
    {
		/* each difference occurs (j - 1)!(N - j)! times */
		factor = 1.0 * Factorial(level - 1) * Factorial(N - level);
		sum += factor * ReturnDiff(level, var);

	    } /* for level ... 
		
	    IJ[0][var-1] = I[var] = sum / Factorial(N);
	    IJ[2][var-1] = J[var] = (d[1].m[var].X - Rtheta - I[var]);
	      */
	    IJ[var - 1] = sum / Factorial(N);
	    IJ[N + var - 1] = (d[1].m[var].X - Rtheta - IJ[var - 1]);
	} /* for var ... */
	/*     Rprintf("\nvar\tI\tJ\tTot\n");
	    	for (var = 1; var <= N; var++)
	  {
	    Rprintf("Var%d \t%4.3lf\t%4.3lf\t%4.3lf\n",
	    var, I[var], J[var], I[var] + J[var]);
	    }*/
	
} /* Partition() */
开发者ID:cran,项目名称:hier.part,代码行数:41,代码来源:xauxil.c

示例12: Factorial

/*
 * Compute and return the factorial of a value, using a recursive algorithm. Zero factorial
 * will return 1.
 * @param value an unsigned integer containing the value for which the factorial will be computed
 * @return an unsigned integer containing the computed factorial of the value
 */
unsigned int Factorial(unsigned int value)
{
    if (value == 1 || value == 0)
    {
		return 1;
    }	
	else
	{
		return (value * Factorial(value-1));
	}	

}
开发者ID:agonzales004,项目名称:CSCI-21-SPRING-2016,代码行数:18,代码来源:lab_22.cpp

示例13: GeneratePermutedList

void GeneratePermutedList( int *list, int listLength, int permute ) {
	for( int i = 0 ; i < listLength ; i++ ) {
		list[i] = i;
	}
	// we can't calculate > 12 factorial, so we can't easily build a permuted list
	if( listLength > 12 ) {
		return;
	}
	// calculate listLength factorial
	int		maxPermute = Factorial( listLength );
	// recursively permute
	PermuteList_r( list, listLength, permute, maxPermute );
}
开发者ID:revelator,项目名称:Revelation,代码行数:13,代码来源:snd_emitter.cpp

示例14: Factorial

int  Factorial(int n){

	if(n == 0){

		return 1;

	} else {

		return(n*Factorial(n-1));
	}

return 0;
}
开发者ID:NerdMcDuck,项目名称:Computer-Architecture,代码行数:13,代码来源:nCr.c

示例15: test60Fact

void test60Fact() {
    std::chrono::time_point<std::chrono::system_clock> start, end;
    std::chrono::duration<double> elapsed_time;
    start = std::chrono::system_clock::now();
    BigInt fact60 = Factorial(60);
    end = std::chrono::system_clock::now();
    elapsed_time = end - start;
#ifdef _PRINT_VALS
    std::cout<< "fact60 took: " << elapsed_time.count() << " computing " << fact60 << std::endl;
#endif
    std::vector<limb_t> actual{18396530,1065373609,393476149,835766904,1949166040,1155626993,1901353954,234881024,0};
    std::cout << "60! Correct? " << testEquals(fact60, actual) << std::endl;   
}
开发者ID:Rosefield,项目名称:BigNum,代码行数:13,代码来源:Test.cpp


注:本文中的Factorial函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。