Saturday 28 January 2012

bc


bc
bc is an important utility provided by unix to do mathematical calculations. This utility can be used as a one line command. you can also program bc  to perform various arithmetic just like that of a C program. It also has a Math library of its own which has functions like sine, cosine, tan and so on, which can be defined by specifying –l option.

For more details on bc you can refer to these url s  on bc.

Example1)
to perform a simple arithmetic  2 + 2,you can bc as follows.
/home/MS$ bc
2+2------------------>type your expression here
4  ---------------------->Ans                           ,
                           
                                




Example2)
To run a command containing an expression and evaluate it using bc,
/home/MS$ echo “ 35.2 – 43.6” | bc
-8.4



Example3)
To use decimal digits you need to specify scale variable.
/home/MS$ bc
6/9
0
Scale=4
6/9
.6666


No comments:

Post a Comment