# Contains? " stdio.h "
# Contains? " stdlib.h "
# Definition? MAX_ORDER? 34
//? Test procedures, the main functions are:
// 1. Output Yang Hui triangle, regardless of whether the output format is symmetrical or not.
//2.? Test the largest number in each row of N-order Yang Hui triangle.
//? The test shows that the maximum number within 34th order in Yang Hui triangle does not exceed the representation range of unsigned shaping (2 32-1).
//? The maximum value of each row of Yang Hui triangle is
//? 1,? 2,? 3,? 6,? 10,? 20,? 35,? 70,? 126,252
//? 462,? 924,? 17 16,? 3432,? 6435,? 12870,243 10,48620,92378, 184756
//? 3527 16,? 705432, 1352078,2704 156,5200300, 10400600,? 20058300,40 1 16600,? 77558760, 155 1 17520
//? 300540 195,? 60 1080390, 1 166803 1 10,2333606220
Invalid? checkMaxNum()
{
Not signed? int? arr 0[MAX _ ORDER+3];
Not signed? int? arr 1[MAX _ ORDER+3];
Not signed? int? MAX[MAX _ ORDER+ 1]; ? //Maximum quantity per line
int? I,j;
//0? 1? 0
//0? 1? 1? 0
//0? 1? 2? 1? 0
//0? 1? 3? 3? 1? 0
memset(arr0,0,sizeof(arr 0)); ? //Clear all elements of the array.
memset(arr 1,0,sizeof(arr 1)); ? //Clear all elements of the array.
memset(max,0,sizeof(max)); //Clear all elements of the array.
arr 0[ 1]= 1;
For what? (I = 1; I<= MAX _ ORDERi++)
{
For what? (j = 1; j & lt= I+ 1; J++)// Calculate all the numbers in line I of Yang Hui Triangle, (i= 1 ...? MAX_ORDER)
{
arr 1[j]= arr 0[j- 1]+arr 0[j];
}
//Output the first line of Yang Hui triangle, (i= 1 ...? MAX_ORDER) and find the largest number in each row.
For what? (j = 1; j & lt= I+ 1; j++)
{
printf("%u\t ",arr 1[j]);
What if? (arr 1[j]& gt; max[i])
max[I]= arr 1[j];
}
printf(" \ n ");
memcpy(arr0,arr 1,sizeof(arr 1));
}
//Print the largest number in each row in Yang Hui triangle.
For what? (I = 1; I<= MAX _ ORDERi++)
{
printf("%u\t ",max[I]);
}
}
//Print Yang Hui triangle
Invalid? printYangHuiTriangle(int? n)
{
//? The most important number of each order in Yang Hui triangle is
//? 1,? 2,? 3,? 6,? 10,? 20,? 35,? 70,? 126,252
//? 462,? 924,? 17 16,? 3432,? 6435,? 12870,243 10,48620,92378, 184756
//? 3527 16,? 705432, 1352078,2704 156,5200300, 10400600,? 20058300,40 1 16600,? 77558760, 155 1 17520
//? 300540 195,? 60 1080390, 1 166803 1 10,2333606220
//The length of the maximum number in the Yang Hui triangle of each order.
int? Width [] =
{
0, 1, 1, 1, 1,2,2,2,2,3,3,
3,3,4,4,4,5,5,5,5,6,
6,6,7,7,7,8,8,8,8,9,
9,9, 10, 10
};
Charles? formatStr[32];
Not signed? int? arr 0[MAX _ ORDER+3];
Not signed? int? arr 1[MAX _ ORDER+3];
int? I,j;
int? Numlun; ? //The length of each number, excluding spaces.
What if? (n & lt 1? ||? n & gt34)
{
Printf ("effective? Parameter ");
Return;
}
NumLen = width [n];
What if? ((numLen? & amp? 1)==0)? //If the length is even
{
num len++;
}
//Calculate the format string and use it when printing numbers.
sprintf(formatStr," %%%du?" ,numLen); ? //If? n=9,? then what format="%3u?" , please note that%% will output a%
memset(arr0,0,sizeof(arr 0)); ? //Clear all elements of the array.
memset(arr 1,0,sizeof(arr 1)); ? //Clear all elements of the array.
arr 0[ 1]= 1;
For what? (I = 1; I < = n; i++)
{
For what? (j = 1; j & lt= I+ 1; J++)// Calculate the first line of Yang Hui triangle, (i= 1 ...? MAX_ORDER)
{
arr 1[j]= arr 0[j- 1]+arr 0[j];
}
For what? (j = 0; j & lt(n-I)*(numLen+ 1)/2; j++)
printf("%c ",0x 20); ? //Leave the left blank to make the printed triangle an isosceles triangle.
//Output the first line of Yang Hui triangle, (i= 1 ...? n)
For what? (j = 1; j & lt= I+ 1; j++)
{
printf(formatStr,arr 1[j]);
}
printf(" \ n ");
memcpy(arr0,arr 1,sizeof(arr 1));
}
}
int? main()?
{?
//check maxnum();
print yanghui triangle(6); ? //Print a 6-line Yang Hui triangle.
printf(" \ n ");
printgyanghui triangle( 12); ? //Print a Yang Hui triangle with 12 lines.
printf(" \ n ");
Return? 0; ?
} This is the C++ version, which can be used for reference for logic control blocks.