Input: Height of Yang Hui's triangle
Output: Print out the front height line of the Yang Hui's triangle in pyramid form
#include <stdio.h>
#include <stdlib.h>
int main (int argc,char **argv)
{
int height;
printf ("Please enter the height of the Yang Hui's triangle \ n");
scanf ("%d", &height);
int **array= (int * *) malloc (sizeof (int *) *height); Dynamically generating two-dimensional arrays
for (int i=0;i{
array[i]= (int *) malloc (sizeof (int) *height);
}
int row,col;
for (row=0;row{
For (col=0;col< (height-row); col++)//Fill space, make output pyramid form
{
printf ("");
}
for (col=0;col<=row;col++)
{
if (col==0| | Row==col)
{
Array[row][col]=1;
printf ("%4d", Array[row][col]); Endpoint Value processing
}
Else
{
The characteristic relationship between the array[row][col]=array[row-1][col]+array[row-1][col-1];//Yang Hui's triangle ranks
printf ("%4d", Array[row][col]);
}
}
printf ("\ n");
}
for (int i=0;i{
Free (array[i]);
}
Free (array);
return 0;
}