• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Factorial函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: TEST

// Tests factorial of negative numbers.
TEST(FactorialTest, Negative) {
  // This test is named "Negative", and belongs to the "FactorialTest"
  // test case.
  EXPECT_EQ(1, Factorial(-5));
  EXPECT_EQ(1, Factorial(-1));
  EXPECT_GT(Factorial(-10), 0);

  // <TechnicalDetails>
  //
  // EXPECT_EQ(expected, actual) is the same as
  //
  //   EXPECT_TRUE((expected) == (actual))
  //
  // except that it will print both the expected value and the actual
  // value when the assertion fails.  This is very helpful for
  // debugging.  Therefore in this case EXPECT_EQ is preferred.
  //
  // On the other hand, EXPECT_TRUE accepts any Boolean expression,
  // and is thus more general.
  //
  // </TechnicalDetails>
}
开发者ID:admiralnlson,项目名称:Rigid3D,代码行数:23,代码来源:test1.cpp


示例17: main

int main()
{
  int i;
  int a[] = {1,2,3,4,5,6,7,8,9};
  printf("Reverse to display an array:\n");
  Reverse(a, 8);
  i = HCF(1470, 693);
  printf("Factorial 5! = %d\n", Factorial(5));
  printf("Greates common devisor 1470 and 693 %d\n", i);
  int n;
  n = 3, i;
  printf("%d\n", n);
  return 0;
}
开发者ID:khakimov,项目名称:secret-octo,代码行数:14,代码来源:hcf.c


示例18: main

void main()
{

	int f1 = 1, f2 = 1, n;

	printf("%d\n", Square(2, 6));
	printf("%d\n", Factorial(5));


	printf("피보나치 수열의 n항 입력: ");
	scanf("%d", &n);

	printf("피보나치 %d항은 %d\n", n, Fibonacci(f2, f1, n));
}
开发者ID:JayStevency,项目名称:KookminUniv,代码行数:14,代码来源:01.c


示例19: test20FactQuad

void test20FactQuad() {
    std::chrono::time_point<std::chrono::system_clock> start, end;
    std::chrono::duration<double> elapsed_time;
    start = std::chrono::system_clock::now();
    BigInt fact = Factorial(20);
    BigInt factSquared = fact * fact;
    factSquared *= factSquared;
    end = std::chrono::system_clock::now();
    elapsed_time = end - start;
#ifdef _PRINT_VALS
    std::cout<< "fact20quad took: " << elapsed_time.count() << " computing " << factSquared << std::endl;
#endif
    std::vector<limb_t> actual{166337208,764515097,443847783,29956932,1554513582,703611904,0,0};
    std::cout << "(20!)^4 Correct? " << testEquals(factSquared, actual) << std::endl;   
}
开发者ID:Rosefield,项目名称:BigNum,代码行数:15,代码来源:Test.cpp


示例20: TestPermutations

void TestPermutations( void ) {
	int	list[SOUND_MAX_LIST_WAVS];
	for( int len = 1 ; len < 5 ; len++ ) {
		common->Printf( "list length: %i\n", len );
		int	max = Factorial( len );
		for( int j = 0 ; j < max * 2 ; j++ ) {
			GeneratePermutedList( list, len, j );
			common->Printf( "%4i : ", j );
			for( int k = 0 ; k < len ; k++ ) {
				common->Printf( "%i", list[k] );
			}
			common->Printf( "\n" );
		}
	}
}
开发者ID:revelator,项目名称:Revelation,代码行数:15,代码来源:snd_emitter.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Fade函数代码示例发布时间:2022-05-30
下一篇:
C++ Factor函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap