#include<stdio.h>#define MAX (5-1)
int gSquare [MAX+1][MAX+1];
/* copy a source row to destination row */void cpRow (int dstRow,int srcRow){
for (int col=0; col<= MAX; col++)
gSquare[dstRow][col]= gSquare[srcRow][col];
}
/* fill all the cells of a given row with zeros */void ZerFil (int row){
for (int col=0; col<= MAX; col++)
gSquare[row][col]=0;
}
/* Print out a given row on screen */void PrnRow (int row){
for (int col=0;col<=MAX;col++)
printf ("%d\t",gSquare [row][col]);
printf ("\n");
}
/* Dynamically define each rows values based on previous rows */void CalcRow (int row){
if (2 * row > MAX+1) {/* we are on lower half *//* copy symmetrically mirror flip */
cpRow(row, MAX-row);
return;
}
cpRow (row, row-1); /* Initiate me as previous row *//* increase required cells */for (int i=row; i<= MAX-row; i++)
gSquare[row][i]++;
}
int main() {
/* Zero the initial row as zero for base of calculation */
ZerFil(0);
PrnRow (0);
for (int row=1; row<=MAX;row++){
CalcRow (row);
PrnRow (row);
}
return0;
}