#include <iostream>#include <iomanip>using namespace STD;int* Setrow (intRowId,int* lastrow) {int* row =New int[RowId]; row[0] =1; for(inti =1; I < rowId-1; i++) {Row[i] = lastrow[i-1] + lastrow[i]; } Row[rowid-1] =1;returnRow;}voidPrintrow (intRowId,int* Row) { for(inti =0; i < rowid;i++) {cout<<SETW (4) <<row[i]; }cout<<endl;}intMain () {int* Tri =New int[2]; tri[0] =1; tri[1] =1;intRowNum =3;Cin>>rowNum;int* ROW;BOOLRET =true; for(inti =3; I <= rowNum; ++i) {if(ret) {row = Setrow (i, tri); Printrow (i, row);Delete[] Tri; Tri = NULL; }Else{tri = setrow (i, row); Printrow (i, tri);Delete[] Row; row = NULL; } ret =!ret; }if(ret) {Delete[] Row; row = NULL; }Else{Delete[] Tri; Tri = NULL; }}
#include <iostream>#include <iomanip>using namespace STD;intMainvoid){intRowNum =3;cout<<"Enter row number here:";Cin>>rowNum;int* row =New int[RowNum +1];//very important! for(inti =0; I < RowNum +1; ++i) {Row[i] =0; }int* p = row; p[1] =1;cout. SETF (Ios::left); for(inti =1; I < RowNum +1; ++i) {//print ith Row for(p + = i; p! = row;--p) {//Highlights cout<<SETW (2) << (*p + = * (P-1)) << SETW (2) <<"'; }cout<<endl; }}
The second paragraph of code i+1 begins to populate line I, just maintain an array
Print Yang Hui triangle