Liunx学习笔记19--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 ~]#
今天就学到这些,发现很多内容非常的有意思。
就近来的学习总结出,要想学好Linux,重要一点是英语要学好。
虽然大致的意思能看明白,但很吃力,
经常金山词霸来查某一个单词的意思,这样往往浪费了很多的时间
在解决单词的意思。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架