用递归函数打印杨辉三角的C源程序用递归函数打印杨辉三角的C源程序
int yangh(int i,int j);
main()
{
register int i,j;
int n;
printf("
Please input the N:");
scanf("%d",&n);
printf("
This program print YangHuiSanJiao:");
for(i=0;i
{
printf("
Line%3d:",i+1);
for(j=0;j<=i;j++)
{
printf("%5d",yangh(i+1,j+1));
}
}
}
int yangh(int i,int j)
{
int result;
if(j==1||i==j)
{
return(1);
}
else
{
result=yangh(i-1,j-1)+yangh(i-1,j);
return(result);
}
}
摘自yesky
阅读(5092) | 评论(3) | 转发(0) |