centos 计算器_linux下的计算器--bc

[root@CentOS4 ~]# bc

bc 1.06

Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.

This is free software with ABSOLUTELY NO WARRANTY.

For details type `warranty'.

(interrupt) use quit to exit.

(interrupt) use quit to exit.

quit

[root@CentOS4 ~]#

--在bc上常用的运算符有:

+    加法

-    减法

*    乘法

/    除法(在没有设置scale精确度时候,自动取整)

^    指数

%    求余数(取模)

在bc上还可以使用

++ 变量

-- 变量

变量 ++

变量 --

[root@CentOS4 ~]# bc

bc 1.06

Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.

This is free software with ABSOLUTELY NO WARRANTY.

For details type `warranty'.

1+2

3

234+23/2*3

267

25^3

15625

100%4

0

100%23

8

quit

[root@CentOS4 ~]#

[root@CentOS4 ~]# bc

bc 1.06

Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.

This is free software with ABSOLUTELY NO WARRANTY.

For details type `warranty'.

scale=2 /*scale=number*/

11/4

2.75

11/3

3.66

quit

[root@CentOS4 ~]#

说明:scale=2 是设置小数精确度。/*备注部分*/

bc还可以运行一个带有复杂运算的程序文件(这属于bc的一个扩展属性),如:

The following is code that uses the extended features of bc to  implement

a  simple program for calculating checkbook balances.

This program is best kept in a file so that it can be used many times  without

having to retype it at every use.

--使用vi建立一个test运算程序:

root@CentOS4 ~]# vi test

scale=2

print ""nCheck book program!"n"

print " Remember,deposits are negative transaction."n"

print "Initial balance?";bal=read()

bal /= 1

print ""n"

while (1){

"current balance = ";bal

"transaction?";trans =read()

if(trans == 0) break;

bal -= trans

bal /= 1

}

~

~

~

"test" [New] 14L, 268C written

[root@CentOS4 ~]# ls

--计算结果:

[root@CentOS4 ~]# bc "test

bc 1.06

Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.

This is free software with ABSOLUTELY NO WARRANTY.

For details type `warranty'.

Check book program!

Remember,deposits are negative transaction.

Initial balance?560

current balance = 560.00

transaction?400

current balance = 160.00

transaction?100

current balance = 60.00

transaction?0

quit

[root@CentOS4 ~]#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值