[root@localhost ~]# bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 1+2*3/4 2
小数计算
1 2 3 4 5 6 7 8
[root@localhost ~]# bc -l bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 1+2*3/4 2.50000000000000000000
可以通过设置scale自行决定精度(小数点位数)
设置bc计算器精确到小数点后10000位
1
scale=10000
计算效果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@localhost ~]# bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 1+2*3/4 2 scale=10000 1+2*3/4 2.500000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000000000\
[root@localhost ~]# bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. p=20 #输入 (2+p)*p #输入 440 #计算结果
使用循环
求1~128的阶乘,在bc中分别输入如下三行代码:
1 2 3
s=1; for(i=1;i<128;i++) s*=i; s
计算结果:
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@localhost ~]# bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. s=1; #输入 for(i=1;i<128;i++) s*=i; #输入 s #输入 30126600184576595448099770775270596923241649186736217990533469005966\ 67207618480809067860692097713761984609779945772783965563851033300772\ 32629777308785186998250027066179124412259762176000000000000000000000\ 0000000000