I just asked another question about pascal triangle about finding sum of 1500th row.
I’m so glad that people answered so quickly, But unfortunately later i realized, i need each individual number on 1500th row.
Here i found an easy way to calculate any number on pascal triangle but when i try to use formula in my code, program crashes in start.
#include"stdio.h"
int factorial(int);
int main()
{
int i=0;
for(i=0; i<1501; i++)
{
printf("%d \n" , (factorial(1500)/factorial(1500-i))/factorial(i) );
}
}
int factorial(int x)
{
if(x<2)
return 1;
else
{
return x*factorial(x-1);
}
}
You need a biginteger library for the results, since
exceeds even the usual
doublerange.But with such a type available, the relation
allows a simple, relatively efficient implementation:
where
outputis whatever output method the library provides.The
value = value*numerator/denominatorpart needs to be adapted if the library doesn’t offer overloads for multiplying/dividing bigintegers and normalints.