杨辉三角

#include<stdio.h>
int main()
{
	int i,j,n,a[31][31];

	while(scanf("%d",&n),n!=0)
	{
	for(i=0;i<n;i++)
	{
		for(j=0;j<=i;j++)
		{
			if((j==0)||(i==j))
			{
				a[i][j]=1;
				if(i==j)
				{
					printf("%d\n",a[i][j]);
				}
				else
					printf("%d ",a[i][j]);
			}
			else
			{
				a[i][j]=a[i-1][j]+a[i-1][j-1];
				printf("%d ",a[i][j]);
			}

		}
	}
	printf("\n");
	}
		return 0;
}

  

原文地址:https://www.cnblogs.com/deosky/p/2355016.html