C语言 求杨辉三角行中,第20行第10列的数位多少?
答案:2 悬赏:50
解决时间 2021-01-17 06:30
- 提问者网友:温旧梦泪无声
- 2021-01-16 09:38
C语言 求杨辉三角行中,第20行第10列的数位多少?
最佳答案
- 二级知识专家网友:西风乍起
- 2021-01-16 11:08
杨辉三角形的结构和元素与二项式系数一一对应,知道行、列就可以利用二项式系数公式求得这个数字,然后再求出这个数的位数即可。二项系数结构行、列都从0开始,所以这里的第20行对应二项式系数结构第19行、第10列对应第9列。举例代码如下:
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int main(void){
int m,n,res,tmp;
for(res=tmp=1,m=19,n=9;n>0;m--,n--)
if(res*=m,tmp*=n,res%tmp==0){
res/=tmp;
tmp=1;
}
for(m=0,tmp=res;tmp;tmp/=10,m++);
printf("This number is %d, it is %d digits.
",res,m);
return 0;
}
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int main(void){
int m,n,res,tmp;
for(res=tmp=1,m=19,n=9;n>0;m--,n--)
if(res*=m,tmp*=n,res%tmp==0){
res/=tmp;
tmp=1;
}
for(m=0,tmp=res;tmp;tmp/=10,m++);
printf("This number is %d, it is %d digits.
",res,m);
return 0;
}
全部回答
- 1楼网友:话散在刀尖上
- 2021-01-16 11:38
我暂时保留我的看法!
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯