题解 | #杨辉三角#
杨辉三角
https://www.nowcoder.com/practice/e671c6a913d448318a49be87850adbcc
#include <stdio.h> long long facts (int x) { int i; long long int sum=1; for(i=1;i<=x;i++) sum=sum*i; return sum; } int compo(int n,int m) { int sum; sum=facts(n)/facts(m)/facts(n-m); return sum; } int main() { int n; scanf("%d",&n); int i,j; for(i=0;i<n;i++) { for(j=0;j<=i;j++) { printf("%5d",compo(i,j)); } printf("\n"); } return 0; }