Simple is not much to say. This is the Yang Hui triangle of the lower triangle.
////main.cpp//YHSJ////Created by madmarical on 15/11/27.//Copyright (c) 2015 COM. All rights reserved.//#include<iostream>using namespacestd;Const intMAXN = -;intANGLE[MAXN][MAXN];intMainintargcConst Char*argv[]) { intINP; CIN>>INP; memset (Angle,0,sizeof(angle)); for(inti =0; I! = INP; ++i) {angle[i][0] =1; Angle[i][i]=1; } for(inti =2; I! = INP; ++i) { for(intj =1; J! = INP; ++j) {Angle[i][j]= Angle[i-1][j-1] + angle[i-1][j]; } } for(inti =0; I! = INP; ++i) { for(intj =0; J! = INP; ++j) {if(Angle[i][j]! =0) {cout<<angle[i][j]<<" "; }} cout<<Endl; } return 0;}
Reflection:
1. How to print a isosceles Yang Hui triangle, with C can be used. Only in C + + words, input and output format control there are problems, but I seem to have seen a classic solution, forget. Go back to the book.
for(h=0;h<Ten; h++) { for(j=0;j<Ten-h;j++) {printf (" "); for(j=0; j<=h;j++) {printf ("%3d", I[h][j]); }} printf ("\ n"); }View Code
2. The control of subscript must be precise ...
C + + print Yang Hui triangle