本文整理汇总了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;
}
示例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;
}
示例3: Factorial
void Factorial(long n)
{
if (n == 0) {
res = 1;
} else {
Factorial(n-1);
res = n * res;
}
}
示例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)
}
示例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;
}
示例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;
}
示例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;
}
示例8: Factorial
/** Computes a factorial. */
static INT Factorial(INT A)
{
if(A == 0)
{
return 1;
}
else
{
return A * Factorial(A - 1);
}
}
示例9: Factorial
/** Computes a factorial. */
static int32 Factorial(int32 A)
{
if(A == 0)
{
return 1;
}
else
{
return A * Factorial(A - 1);
}
}
示例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);
}
示例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() */
示例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));
}
}
示例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 );
}
示例14: Factorial
int Factorial(int n){
if(n == 0){
return 1;
} else {
return(n*Factorial(n-1));
}
return 0;
}
示例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;
}