`[`

bc`] [`

options`]`

files

- -c
Do not invoke

**dc**; compile only. (Since**bc**is a preprocessor for**dc**,**bc**normally invokes**dc**.)- -l
Make available functions from the math library.

- x
Variable

**x**.- x[

]*i* Element

of array*i***x**.

can range from 0 to 2047 and can also be an expression.*i*- x(y,z)
Call function

**x**with parameters**y**and**z**.- ibase =
*n* Numbers that are input (e.g., typed) are read as base

(default is 10).*n*- obase =
*n* Numbers displayed are in base

(default is 10). Note: Once*n***ibase**has been changed from 10, use digit "A" to restore**ibase**or**obase**to decimal.- scale =
*n* Display computations using

decimal places (default is 0, meaning that results are truncated to integers).*n***scale**is normally used only for base-10 computations.- if (

) {*rel-expr*

}*statements* Do one or more

if relational expression*statements*

is true; for example:*rel-expr*

.**if(x==y) i = i + 1**- while (

) {*rel-expr*

}*statements* Repeat one or more

while*statements*

is true; for example:*rel-expr***while(i>0) {p = p*n; q = a/b; i = i-1}**- for (

;*expr1*

;*rel-expr*

) {*expr2*

}*statements* Similar to

**while**; for example, to print the first 10 multiples of 5, you could type:**for(i=1; i<=10; i++) i*5**- break
Terminate a

**while**or**for**statement.- define

(*j*

) {*k* Begin the definition of function

having a single argument*j*

. Additional arguments are allowed, separated by commas. Statements follow on successive lines. End with a }.*k*- auto

,*x**y* Set up

and*x*

as variables local to a function definition, initialized to 0 and meaningless outside the function. Must appear first.*y*- return(

)*expr* Pass the value of expression

back to the program. Return 0 if*expr***(***expr***)**is left off. Used in function definitions.- sqrt(

)*expr* Compute the square root of expression

.*expr*- length(

)*expr* Compute how many digits are in

.*expr*- scale(

)*expr* Same, but count only digits to the right of the decimal point.

- s(

)*angle* Compute the sine of

, a constant or expression in radians.*angle*- c(

)*angle* Compute the cosine of

, a constant or expression in radians.*angle*- a(

)*n* Compute the arctangent of

, returning an angle in radians.*n*- e(

)*expr* Compute

**e**to the power of

.*expr*- l(

)*expr* Compute natural log of

.*expr*- j(
*n***,***x***)** Compute Bessel function of integer order

.*n*- arithmetic
+

`-`

`*`

/ % ^- unary
`-`

++ --- assignment
=+ =

`-`

=* =/ =% =^ =- relational
< <= > >= == !=

- /* */
Enclose comments.

- ( )
Control the evaluation of expressions (change precedence). Can also be used around assignment statements to force the result to print.

- { }
Used to group statements.

- [ ]
Array index.

- "

"*text* Use as a statement to print

.*text*

Interactively perform arbitrary-precision arithmetic or convert numbers
from one base to another. Input can be taken from

or read from the standard input. To exit, type
*files***quit** or

.*EOF*

**bc** is a language (and compiler) whose syntax resembles that of C.
**bc** consists of identifiers, keywords, and symbols, which
are briefly described below. Examples follow at end.

An identifier is a single character, consisting of the lowercase letters a-z. Identifiers are used as names for variables, arrays, and functions. Within the same program you may name a variable, an array, and a function using the same letter. The following identifiers would not conflict:

**ibase**, **obase**, and **scale** store a value.
Typing them on a line by themselves
displays their current value. More commonly, you would change
their values through assignment. Letters A-F are treated
as digits whose values are 10-15.

A semicolon or a newline separates one statement from another. Curly braces are needed only when grouping multiple statements.

These are available when **bc** is invoked with **-l**.
Library functions set **scale** to 20.

These consist of operators and other symbols. Operators can be arithmetic, unary, assignment, or relational.

Note below that when you type some quantity (a number or expression), it is evaluated and printed, but assignment statements produce no display.

ibase = 8Octal input.

20Evaluate this octal number.`16`

Terminal displays decimal value.

obase = 2Display output in base 2 instead of base 10.

20Octal input.`10000`

Terminal now displays binary value.

ibase = ARestore base 10 input.

scale = 3Truncate results to 3 places.

8/7Evaluate a division.`1.001001000`

Oops! Forgot to reset output base to 10.

obase=10Input is decimal now, so "A" isn't needed.

8/7`1.142`

Terminal displays result (truncated).

The following lines show the use of functions:

define p(r,n){Function p uses two arguments.

auto vv is a local variable.

v = r^nr raised to the n power.

return(v)}Value returned.

scale=5

x=p(2.5,2)x = 2.5 ^ 2

xPrint value of x. 6.25

length(x)Number of digits. 3

scale(x)Number of places right of decimal point. 2