C language Print Yang Hui's triangle with one array and two dimensional array
#include <stdio.h>/* using one-dimensional arrays and two-dimensional arrays to print Yang Hui's triangles
/#define N-
#define M
one_dim_array (int *a,int num) Prints
{
int i,j,k with a one-dimensional array;
printf ("%5d\n", a[0]); Print first row
of data for (i=2;i<=num;i++)
{
for (j=i-1;j>0;j--)
a[j]=a[j]+a[j-1];////Every row of data from right to left
for (k=0;k<i;k++)//print data for each line
printf ("%5d", A[k]);
printf ("\ n")
;
}
int main ()
{
int arr[n]={1,0};//Here defines a one-dimensional array with the first item 1 and the other item 0
int a[m][m];
int n;
int i,j;
printf ("Input The Lines:");
scanf ("%d", &n);
printf ("Using one_dim_array:\n");
One_dim_array (arr,n);
printf ("Using double_dim_array:\n");
for (i=0;i<m;i++)
{
a[i][0]=1;
a[i][i]=1;
}
for (i=2;i<m;i++) for
(j=1;j<i;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
for (i=0;i<m;i++)
{
for (j=0;j<=i;j++)
printf ("%5d", A[i][j));
printf ("\ n");
}
return 0;
Running results under Linux: