Monday, 6 February 2017

Pascal's Triangle C Language

Pascal's Triangle C Language Code

Pascal's triangle is a triangular array of the binomial coefficients. in which each row , second character and one before of last digit is sum two digit left to right from previous row.

Image Source Wikipedia 

/*   ################################
     Girfa Student Help
     Pascal Triangle
     for more visit : http://girfahelp.blogspot.in/p/c-language.html
     ################################
*/
#include<stdio.h>
void main()
{
    int rows,i,j,k;
    printf("Enter the number of rows>> ");
    scanf("%d",&rows);
    for (i = 0; i < rows; i++)
    {
     int val = 1;
     for (j = 1; j < (rows - i); j++)
     {
         printf("   ");
     }
     for (k = 0; k <= i; k++)
     {
         printf("      %d",val);
         val = val * (i - k) / (k + 1);
     }
     printf("\n\n");
    }

}


No comments:

Post a Comment