yanghui Triangle

来源:互联网 发布:网络出版物的种类 编辑:程序博客网 时间:2024/06/03 03:19

My Personal Solution using two dimensional array

This is my c form code.

#include <stdio.h>#define N 20 // dimension int main() {    int yTri[N][N] = {0};    for(int row = 0; row < N; ++row){        for(int col=0; col<= row; ++col){            if(col==0){                yTri[row][col] = 1;    // the first element in each row set to 1            } else {                yTri[row][col] = yTri[row - 1 ][col - 1] + yTri[row - 1 ][col] ; // the previous row and column addition to produce the current number            }            printf("%4d", yTri[row][col]);        }        printf("\n");    }    return 0;}
0 0