#include<stdio.h>
#include <conio.h>
void main()
{
int line,c,n,x;
void pasc(int);
printf("\n\nInsert, how much line do you want: ");
scanf("%d",&line);
printf("\n\n\n");
printf("\nPascal's Triangle Is : (press enter)\n");
for(x=line-1;x>=0;x--)
        printf("   ");
printf("  1\n\n");
for(n=2;n<=line;n++)
{
    for(c=line-n;c>=1;c--)
        printf("   ");
 pasc(n);
 printf("\n");
  getche();
}
}
void pasc(int n)
{
    int r;
 long fact(int);
        for(r=0;r<=n;r++)
            printf("%3ld   ",fact(n)/(fact(n-r)*fact(r)));
}
  long fact(int v)
{
  if(v==1||v==0)
      return(1);
  else
      return(v*fact(v-1));

}

i don't know, what's wrong with my code. if you run, you will get the wrong output ini 13th line... oh yeah, i'm indonesian, so please forgive me, if my english is very bad.. :mrgreen:

What happens when you compute fact(13)? The number is too large to be represented by a long (which has range up to 2^31-1, approximately 4 billion). That messes up the computations at that point.

so, what must i do? i've changhe long to long int, but there's no efeect... :rolleyes:

You could use ULONGLONG but that just shifting your problem to a later stage. The other option is to rewrite your function, there are plenty examples of Pascal-triangles here ons daniweb.

regards Niek

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.