0
#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:

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by Nick Evan
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.