Search C Program

Pascal Triangle

1
1 1
1 2 1
1 3 3 1 
1 4 6 4 1

long fact(int);

int main()
{
   int i, j;
   for (i=0;i<5;i++)
   {
      for(j=0;j<=i;j++)
      {
         printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
      }
      printf("\n");
   }
   return 0;
}
 
long fact(int n)
{
    int i;
    long f = 1;
    for(i=1;i<=n;i++)
      f = f*i;
    return f;
}


Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C

8 comments:

  1. #include
    void main()
    {
    int i,num=1;
    for(i=1;i<=5;i++)
    {
    printf("%d",num);
    num=num*11;
    printf("\n");
    }
    }

    ReplyDelete
    Replies
    1. good observation

      Delete
    2. THE SAME PATTERN IS PRINTED 5 TIME. WHY???

      Delete
    3. SRY IT WAS MY MISTAKE I FOUND IT

      Delete
    4. dude Soumya Sourav ....wrong observation in 6th iteration

      Delete
  2. public class PascalTriangle {

    public static void main(String[] args) {

    int rows = 10;


    for(int i =0;i<rows;i++) {
    int number = 1;
    System.out.format("%"+(rows-i)*2+"s","");
    for(int j=0;j<=i;j++) {
    System.out.format("%4d",number);
    number = number * (i - j) / (j + 1);

    }
    System.out.println();
    }

    }
    }

    ReplyDelete
  3. int i,j,k,b,m=1;
    int mul(int);
    int main()
    {
    for(i=1;i<=5;i++)
    {



    printf("%d",m);
    mul(m);




    printf("\n");
    }
    }
    int mul(int i)
    {
    m=m*11;



    return m;
    }

    ReplyDelete
  4. #include
    int main()
    {
    int rows, coef = 1, i, j;
    printf("Enter number of rows: ")
    scanf("%d",&rows);
    for(i=0; i<rows; i++)
    {
    for(j=0; j <= i; j++)
    {
    if (j==0 || i==0)
    coef = 1;
    else
    coef = coef*(i-j+1)/
    printf("%4d", coef);
    }

    ReplyDelete