void main()
{
clrscr();
int n,r;
cout<<"Enter n and r:\n";
cin>>n>>r;
long p=Fact(n)/(Fact(r)*Fact(n-r));
cout<<p;
getch();
}
Exemplo n.º 2
0
unsigned int Fact(const unsigned int n){
	static unsigned int f[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
	if(n < 10)
		return f[n];
	 
	return(Fact(n-1)*n);
}
Exemplo n.º 3
0
int Fact(int nombre) {
	if (nombre < 2)
		return 1;
	else
		return nombre * Fact(nombre - 1);

}
// Factorial(n) = n * Factorial(n-1).		Factorial(0) = Factorial(1) = 1
int Fact(int n)
{
	if(n <= 1)
		return 1;

	return n * Fact(n-1);
}
Exemplo n.º 5
0
/*---------------------------------------------------------------------------*/
PPINT CombNoRep(INT n, INT k, PINT pNComb) {
	INT NComb, nk;
	INT i, j;
	PPINT S;

	NComb = 0;
	nk = n - k;

	(*pNComb) = Fact(n) / (Fact(k) * Fact(nk));

	S = (PPINT) GetMem2D(*pNComb, k, (SIZE) sizeof(INT), "CombNoRep");

	/* fprintf(stderr,"Convinaciones=%d.\n",Fact(n)/(Fact(k)*Fact(nk)) );
	 fprintf(stderr,"Fact(%d)=%20d, Fact(%d)=%20d, Fact(%d)=%20d.\n",
	 n,Fact(n),k,Fact(k),nk,Fact(nk));
	 fprintf(stderr,"n=%d, k=%d.\n", n, k);
	 fprintf(stderr,"NComb=%d, pNComb=%d.\n",NComb, (*pNComb));
	 */

	for (i = 0; i < k; i++)
		S[NComb][i] = i;

	/*PrintVINT(stderr,S[NComb],k);*/
	while (S[NComb][0] < nk) {
		NComb++;
		CopyVINT(S[NComb], S[NComb - 1], k);

		if (S[NComb][k - 1] < n - 1)
			S[NComb][k - 1]++;
		else {
			j = 1;
			while (S[NComb][k - 1 - j] == n - 1 - j)
				j++;
			S[NComb][k - 1 - j]++;
			for (i = k - j; i < k; i++)
				S[NComb][i] = S[NComb][i - 1] + 1;
		}
		/*	fprintf(stderr,"NComb=%d = ",NComb);
		 PrintVINT(stderr,S[NComb],k);
		 */
	}
	return S;
}
Exemplo n.º 6
0
Arquivo: 25.c Projeto: clsera/CLab
long int Fact(int n)
{
	long int x;
	if (n > 1)
	{
		x = Fact(n - 1);
		return n * x;
	}
	else 
	{
		return 1;
	}
}
Exemplo n.º 7
0
/*
 *  FUNCTION: CalcWinnings
 *
 *  CATEGORY: Draw Function
 *
 *  PURPOSE:  In loto's games get the winners bets per category
 *
 *  PARAMETERS:
 *            (I) WORD NumResults     - Number of results
 *            (I) WORD WinDegree      - How many hits to look for
 *            (I) WORD CorrectBets    - How many are the right bets
 *            (I) WORD InCorrectBets  - How many are the no right bets
 *
 *  RETURN VALUE:
 *            The number of winners bets
 *
 *  COMMENTS:
 *
 */
DWORD       CalcWinnings (WORD  NumResults,
                          WORD  WinDegree,
                          WORD  CorrectBets,
                          WORD  InCorrectBets)
{
    WORD      _idx;
    DWORD     _count;
    DWORD     _correct_combination;

    _count = 1;
    for ( _idx = 0; _idx < (NumResults - WinDegree); _idx++ )
    {
        _count *= (DWORD) (InCorrectBets - _idx);
    }

    _count /= Fact (NumResults - WinDegree);

    // Get how many groups of correct combinations are in the CorrectBets
    _correct_combination = Fact (CorrectBets) / (Fact (WinDegree) * Fact (CorrectBets - WinDegree));

    _count *= _correct_combination;

    return _count;
}
Exemplo n.º 8
0
SectionForm::SectionForm(QWidget *parent)
    : Form(parent)
{
    section = Fact();

    QHBoxLayout *layout = new QHBoxLayout(this);

    nameInput = new QLineEdit();

    layout->addStretch(1);
    layout->addWidget(new QLabel("Name: "));
    layout->addWidget(nameInput);
    layout->addStretch(1);
    
    connect(nameInput, SIGNAL(textChanged(QString)), this, SLOT(checkValidity()));
}
Exemplo n.º 9
0
void Calculatrice::fonctionBoutonFact() {
	if (base == 2)
		binDec();
	if (base == 8)
		octDec();
	if (base == 16)
		hexDec();

	QString nbtxt = ligne->text();
	double nombre = floor(nbtxt.toDouble());
	nombre = Fact(nombre);
	numbersloved = true;
	ligne->setText(QString::number(nombre));
	if (base == 2)
		decBin();
	if (base == 8)
		decOct();
	if (base == 16)
		decHex();
}
Exemplo n.º 10
0
unsigned long Splines::C(unsigned long n, unsigned long i)
{
  return Fact(n) / (Fact(i) * Fact(n - i));
}
Exemplo n.º 11
0
Arquivo: 25.c Projeto: clsera/CLab
int main()
{
	printf("%ld\n", Fact(4));
    return 0;
}