杭电oj 2032 杨辉三角 C语言

#include
#include

void main()
{
	int n, i, ** nums, j;
	while (~scanf_s("%d", &n))
	{
		nums = (int**)malloc(n * sizeof(int*));
		for (i = 0; i < n; i++)
		{
			nums[i] = (int*)malloc((i + 1) * sizeof(int));
			nums[i][0] = nums[i][i]=1;
			for (j = 0; j <= i; j++)
			{
				if (j > 0 && j < i)nums[i][j] = nums[i - 1][j - 1] + nums[i - 1][j];
				printf("%d ", nums[i][j]);
			}
			printf("\n");
		}
		printf("\n");
	}
}

你可能感兴趣的:(c语言,算法,数据结构)