**Enter row number: 4
Sum of numbers in row 5 is 31. Sum of all numbers above 4 is 15.
this should be the output look like..
can someone help me? thanks.
**Enter row number: 4
Sum of numbers in row 5 is 31. Sum of all numbers above 4 is 15.
this should be the output look like..
can someone help me? thanks.
The elements of Pascal's triangle are the statistical combination of the given row and column, if you consider Pascal's triangle as a right triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
...
Each element of Pascal's triangle is the result of nCr, where n is the row number, starting at 0, and r is the column number, also starting at 0. As far as I can tell, Combination is not a function in the Math library, but really it should be.
public static long Factorial(byte nValue)
{
long nFact = 1L;
// If nValue > 20, this will generate a numberic overflow, even using long.
if (nValue < 0)
return 0L;
else if (nValue < 2)
return 1L;
for (long i=nValue; i > 1; --i)
nFact *= i;
return nFact;
}
public static int Combination(int nSetSize, int nChosen)
{
int nLow;
int nCombo = 1;
if (nChosen > nSetSize-nChosen)
nLow = nChosen;
else
nLow = nSetSize - nChosen;
for (int i=nLow+1; i <= nSetSize; ++i)
nCombo *= i;
nCombo /= Factorial(nSetSize - nLow);
return nCombo;
}
This code has not been tested, so there might be a bug or two in it.
There is also a good article on this stuff, including producing Pascal's triangle here.
@gelmi
Are you in DOS mode?
Actually the sum of any row a Pascal's Triangle is 2^n, where n is the row number, starting at 0. The sum of all values above a certain row is (2^n)-1. So the sum of all values in row 5 is 2^5 = 32. The sum of all values above row 5 is 2^5 - 1 = 32-1 = 31.