In the shell, the following assigns an approximation of the first
ten digits of 'π'
to the variable x:
x=$(printf "%s\n" 'scale = 10; 104348/33215' | bc)
The following bc program prints the same approximation of 'π'
,
with a label, to standard output:
scale = 10
"pi equals "
104348 / 33215
The following defines a function to compute an approximate value
of the exponential function (note that such a function is
predefined if the -l
option is specified):
scale = 20
define e(x){
auto a, b, c, i, s
a = 1
b = 1
s = 1
for (i = 1; 1 == 1; i++){
a = a*x
b = b*i
c = a/b
if (c == 0) {
return(s)
}
s = s+c
}
}
The following prints approximate values of the exponential
function of the first ten integers:
for (i = 1; i <= 10; ++i) {
e(i)
}