Search This Blog

Thursday, March 25, 2010

//Pascal's Triangle- the mathematical way
class Pascal
{
double fact(double n)
{

return (n > 1) ? n * fact(n - 1) : 1;

}
double ncr(int n, int r)
{

return fact(n) / (fact(r) * fact(n - r));

}
void generate()
{
for (int i = 0; i < 15; i++)
{
for (int j = 0; j <= i; j++)
{
System.out.print((int)ncr(i, j));
}
System.out.println(" ");
}
}
}

//As per Request from Tanmoy.
Discussing Java application programming across the barrier of classroom for the young minds.

No comments:

Post a Comment