Created
December 3, 2018 07:01
-
-
Save XcqRomance/62d5977ba1da9fea6131b4cf08494de1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 帕斯卡三角形 杨辉三角 | |
int** generate(int numRows, int** columnSizes) { | |
if(numRows<=0) return NULL; | |
int **ret=(int **)malloc(numRows*sizeof(int *)); | |
int row,column; | |
*columnSizes = (int *)malloc(numRows*sizeof(int)); | |
//printf("成功初始化数组与行数矩阵\n"); | |
for(row=0;row<numRows;row++) | |
{(*columnSizes)[row]=row+1; | |
ret[row]=(int*)malloc((row+1)*sizeof(int)); | |
} | |
for(row=0;row<numRows;row++) | |
{ | |
ret[row][0]=1; | |
ret[row][row]=1; | |
} | |
//printf("初始化数组成功\n"); | |
if(numRows<=2){ | |
return ret; | |
} | |
for(row=2;row<numRows;row++){ | |
for(column=1;column<row;column++) | |
ret[row][column]=ret[row-1][column-1]+ret[row-1][column]; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment