#include
#define N 10
int c(int x,int y);
void main()
{
int i,j,n=13;
printf("N=");
while(n>12)
scanf("%d",&n); /*控制输入正确的值以保证屏幕显示的图形正确*/
for(i=0;i
for(j=0;j<24-2*i;j++) printf(" "); /*控制输出第i行前面的空格*/
for(j=1;j printf("\n");
}
}
int c(int x,int y) /*求杨辉三角形中第x行第y列的值*/
{
int z;
if((y==1)||(y==x+1)) return 1; /*若为x行的第1或第x+1列,则输出1*/
z=c(x-1,y-1)+c(x-1,y); /*否则,其值为前一行中第y-1列与第y列值之和*/
return z;
}
#include
#include
#include
int main(void)
{
int n = 0;
int **a;
int i, j, k;
printf("Input n:");
scanf("%d", &n);
a = (int **)malloc(sizeof(int *)*n);
for (i = 0; i < n; ++i)
{
a[i] = (int *)malloc(sizeof(int)*n);
memset(a[i], 0, sizeof(int)*n);
}
for (i = 0; i < n; ++i)
{
for (j = i; j < n; ++j)
{
if (i==0)
a[i][j]=1;
else
a[i][j] = a[i][j-1] + a[i-1][j-1];
}
}
for (i = 0; i < n; ++i)
{
for (j = 0; j < n; ++j)
{
if (a[i][j] == 0)
printf(" ");
else
printf("%8d", a[i][j]);
}
printf("\n");
}
free(a);
return 0;
}