Tuesday 11 June 2013

PASCALS TRIANGLE

PASCALS TRIANGLE

#include<stdio.h>
#include<conio.h>
int main() {

        int a[15][15], i, j, rows, num = 25, k;
        printf("----------------------------------------------------------------------\n");
        printf("------------------made by BEST BLOG for TECHNOLOGY LOVERS -----------------\n");
        printf("----------------------------------------------------------------------\n");
        printf("\n\n\t\t C PROGRAM OF PASCALS TRIANGLE \n");
        printf("\n Enter the number of rows you want to show : ");
        scanf("%d", &rows);
        printf("\n\n\n");
        for (i = 0; i < rows; i++) {
               for (k = num - 2 * i; k >= 0; k--)
                     printf(" ");
               for (j = 0; j <= i; j++) {
                     if (j == 0 || i == j) {
                         a[i][j] = 1;
                     } else {
                         a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
                     }
                     printf("%4d", a[i][j]);
               }
               printf("\n");
         }
         getch();
}

No comments:

Post a Comment