int func(int n, int k)
{
if (k == 1 || k == n )
return 1;
if (k<1 || k>n)
return 0;
else
return func(n - 1, k - 1) + func(n - 1, k);
}
void YHSJ(){
int N = 5;
for (int i = 1; i <= 5; ++i){
for (int j = 1; j <= N; ++j)
{
int tmp = func(i, j);
if (tmp!=0)
cout << tmp << " ";
}
cout << endl;
}
cout << endl;
}
递归法输出杨辉三角
最新推荐文章于 2023-12-23 10:18:01 发布