c++

nametapa 2009-03-08 02:36:05
Pascal’s triangle
C(m,0) = 1 and C(m, m) = 1 for m >= 0.
C(m,n) = C(m-1, n-1) + C(m-1, n) for m > n > 0.

Enter number n: 3
Result:
1
1 1
1 2 1
1 3 3 1


我的尝试:
#include <iostream>
using namespace std;

void pascal(int);
int coe(int,int);

void main ()

{
int row;
cout<<"enter number n:"<<endl;
cin>>row;

pascal(row);
}
return 0;
}
void pascal(int row)
{
for (int i =1; i<= row; i++)
{
for {int b=1; b<=1; b++)
cout<<coe(i,m)<<'';
cout<<endl;
}
}
int coe(int m,int n)
{
if (m>=0 || n<=1)
return 1;
else
return coe(m-1,n-1) + coe(m-1,n);


return 0;


我试过了很多次了但还是不能,请问谁能脚我完整的coding?
...全文
91 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Treazy 2009-03-09
  • 打赏
  • 举报
回复

#include <cstdio>
#include <assert.h>

int Fun(int m, int n)
{
assert(m >= 0 && n >= 0);
if(0 == n || m == n)
{
return 1;
}

return m > n ? Fun(m-1, n-1) + Fun(m-1, n) : 0;
}

int main(int argc, char** argv)
{
for(int i = 0; i < 10; ++i)
{
for(int j = 0; j <= i; ++j)
{
printf("%4d ", Fun(i, j));
}
printf("\n");
}

return 0;
}


Please take it as a reference!
  • 打赏
  • 举报
回复
mark先

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧