杨辉三角形(输出不超过10行)

None.gif #include  < stdio.h >
None.gif#include 
< conio.h >
None.gif
#define  N 10
None.gif
void  yanghui( int  a[][N], int  n);
None.gif
void  main()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif  
int i,j,n,b[N][N];
InBlock.gif  printf(
"Enter n:");
InBlock.gif  scanf(
"%d",&n);
InBlock.gif  yanghui(b,n);
InBlock.gif  
for(i=0;i<n;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
for(j=0;j<=i;j++)
InBlock.gif       printf(
"%-4d",b[i][j]);
InBlock.gif     printf(
"\n");
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gif
void  yanghui( int  a[][N], int  n)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif  
int i,j;
ExpandedSubBlockStart.gifContractedSubBlock.gif  
for(i=0;i<n;i++)     /**//*生成三角形边上元素*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif      a[i][
0]=1;       /**//*即:0列与i行i列的元素为1*/
InBlock.gif      a[i][i]
=1;
ExpandedSubBlockEnd.gif    }

InBlock.gif  
for(i=2;i<n;i++)
InBlock.gif    
for(j=1;j<i;j++)
InBlock.gif      a[i][j]
=a[i-1][j-1]+a[i-1][j];
ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/qixin622/archive/2007/01/17/622196.html

你可能感兴趣的:(杨辉三角形(输出不超过10行))