题解 | 杨辉三角

杨辉三角

https://www.nowcoder.com/practice/8c6984f3dc664ef0a305c24e1473729e

#include <stdio.h>

int main() {
	int n = 0;
	int arr1[34] = { 1 };
	int arr2[34] = { 1 };
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		if (i % 2) {
			for (int j = 0; j < i; j++) {
				printf("%d ", arr1[j]);
				arr2[j + 1] = arr1[j] + arr1[j + 1];

			}
		}
		else {
			for (int j = 0; j < i; j++) {
				arr1[j + 1] = arr2[j] + arr2[j + 1];
				printf("%d ", arr2[j]);
			}
		}
		printf("\n");
	}
	return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务