
Create a program to continually calculate and output the next decimal digit of   



π


{\displaystyle \pi }

   (pi).

The program should continue forever (until it is aborted by the user) calculating and outputting each decimal digit in succession.

The output should be a decimal sequence beginning   3.14159265 ...



Note: this task is about   calculating   pi.   For information on built-in pi constants see Real constants and functions.



Related Task Arithmetic-geometric mean/Calculate Pi

#!/usr/bin/bc -l
 
scaleinc= 20
 
define zeropad ( n ) {
    auto m
    for ( m= scaleinc - 1; m > 0; --m ) {
        if ( n < 10^m ) {
            print "0"
        }
    }
    return ( n )
}
 
wantscale= scaleinc - 2
scale= wantscale + 2
oldpi= 4*a(1)
scale= wantscale
oldpi= oldpi / 1
oldpi
while( 1 ) {
    wantscale= wantscale + scaleinc
    scale= wantscale + 2
    pi= 4*a(1)
    scale= 0
    digits= ((pi - oldpi) * 10^wantscale) / 1
    zeropad( digits )
    scale= wantscale
    oldpi= pi / 1
}