# Thread: Pascal's Triangle Program Only Accurate to 12 Rows

1. ## Pascal's Triangle Program Only Accurate to 12 Rows

Hello, I'm new to programming in C, so I've been working on some of the challenges. I've completed the Pascal's Triangle challenge, however my program doesn't give accurate values past the 12th row of the triangle. I'm wondering if this is a logic error on my part, or maybe a memory problem with my factorial function? Any help is greatly appreciated.

Code:
```#include <stdio.h>

int factorial( int n )
{
if ( n <= 1 )
return 1;
else
return n * factorial( n - 1 );
}

int main()
{
int n;
int r;
int value = 0;

do {
n = 0;
r = 0;
printf( "Input the row#: " );
scanf( "%d", &n );
printg( "Input the value's position within the row: " );
scanf( "%d", &r );

if ( r > n )
printf( "That is not a valid position within Pascal's Triangle\n" );
} while ( r > n );

value = factorial( n ) / (factorial( r ) * factorial( n - r ));

printf( "The value at row-%d, position-%d is %d\n", n, r, value );

return 0;
}```

2. You're probably running into the upper limit of the range of int.

3. Ah, I see. Well I guess that makes sense, I've never programmed in a language that didn't at least have a longint datatype. Is there any work-around for this, other than a more efficient algorithm? Thanks for the insanely speedy reply!

4. Well, this language does have a longint datatype.

5. I'm an idiot, I just assumed that when most searches initially just showed the basic datatypes, that was it. Thanks again.

6. It may be the case that the range of int is the same as that of long. If you are compiling with respect to the 1999 edition of the C standard then you could use unsigned long long. However, you would eventually run into an upper limit again. If you find that problematic, consider the use of a bignum library like the GMP.

7. long long int did the trick. Even an unsigned long int was too small. The GMP looks pretty sweet, I'll definitely be checking it out. Thanks once more!