package test;public class YangHui { /**打印杨辉三角
* @param args
*
*/
private long c=0;
public long getJieCheng(long n){//计算n的阶层
long m=n;
if(m!=0||m!=1)
for (int i=1;i<=m;i++)
{c*=m;}
else c=1;
return c;
}public long getErXiangShi(long n,long k){//计算任意的二项式
return getJieCheng(n)/getJieCheng(n-k)*getJieCheng(k);
}
public void c(long n){//打印二项式展开式
for(int i=0;i<=n;i++)
for(int j=0;j<=i;j++)
System.out.println(getErXiangShi(i,j));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
YangHui a=new YangHui();
//a.m=Long.parseLong(args[0]);
//a.c(10);
System.out.println(a.c);
}}
* @param args
*
*/
private long c=0;
public long getJieCheng(long n){//计算n的阶层
long m=n;
if(m!=0||m!=1)
for (int i=1;i<=m;i++)
{c*=m;}
else c=1;
return c;
}public long getErXiangShi(long n,long k){//计算任意的二项式
return getJieCheng(n)/getJieCheng(n-k)*getJieCheng(k);
}
public void c(long n){//打印二项式展开式
for(int i=0;i<=n;i++)
for(int j=0;j<=i;j++)
System.out.println(getErXiangShi(i,j));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
YangHui a=new YangHui();
//a.m=Long.parseLong(args[0]);
//a.c(10);
System.out.println(a.c);
}}
错误a.c();
这句比较强!!
函数的命名使用拼音吗?阶层的拼音你写对了吗????
long c=1;
if (m != 0 || m != 1)
for (int i = 1; i <= m; i++) {
c *= m;
}
else
c = 1;
return c;
} public long getErXiangShi(long n, long k) {//计算任意的二项式
return getJieCheng(n) / getJieCheng(n - k) * getJieCheng(k); } public void c(long n) {//打印二项式展开式
for (int i = 0; i <= n; i++){
for (int j = 0; j <= i; j++)
System.out.print(getErXiangShi(i, j)+" ");
System.out.println();
}
} public static void main(String[] args) {
YangHui a = new YangHui();
a.c(10);
}
}不过结果是(前6行)....
1
1 1
1 4 16
1 6 108 729
1 9 256 6912 65536
1 12 460 21087 800000 9765625 貌似你的算法有问题..
1 1
1 4 16
1 6 108 729
1 9 256 6912 65536
1 12 460 21087 800000 9765625
1 14 728 46656 2985984 145800000 2176782336
1 17 1052 86832 7808256 643390625 38423222208 678223072849
1 20 1436 144936 16777216 1941806250 195689447424 13816758796288 281474976710656
1 23 1880 224181 31737344 4729253125 669462604992 79764357737246 6499837226778624 150094635296999121
1 25 2384 327834 54869504 10000000000 1822500000000 305015925620910 41943040000000000 3874204890000000000 7766279631452241920我在eclipse里能打印 10行,但是最后输出的不是一,有点郁闷啊
} public long getErXiangShi(long n, long k) {//计算任意的二项式
return getJieCheng(n) /( getJieCheng(n - k) * getJieCheng(k)); } public void c(long n) {//打印二项式展开式
for (int i = 0; i <= n; i++){
for (int j = 0; j <= i; j++)
System.out.print(getErXiangShi(i,j)+" ");
System.out.println();
}
} public static void main(String[] args) {
YangHui a = new YangHui();
a.c(10);
}
}
if(n <= 1)return 1;
else{
return n * getJieCheng(n-1);
}
} public long getErXiangShi(long n, long k) {//计算任意的二项式
return getJieCheng(n) / (getJieCheng(n - k) * getJieCheng(k)); } public void c(long n) {//打印二项式展开式
for (int i = 0; i <= n; i++){
for (int j = 0; j <= i; j++)
System.out.print(getErXiangShi(i, j)+" ");
System.out.println();
}
} public static void main(String[] args) {
YangHui a = new YangHui();
a.c(10);
}
}结果
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1