BC number theory programs

BC (version 1.07.1) (see the manual) is a programming language that supports arbitrary precision integer arithmetic calculations with interactive execution of statements. It is an idiosyncratic programming language which closely resembles parts of the C language. While it is somewhat slow for some purposes (all code is executed as it is read), the author has found bc very useful in teaching and research. The code is very easy to read and students can see directly how an algorithm has been implemented. It is also useful as a template for harder-to-write, but faster C code.

Bugs and idiosyncrasies:

  1. When using the if-else construction, insert a "\", as follows:
              else{ statement2}
    Alternatively, as pointed out by Anton Stiglic, use the construction
  2. The continue statement only works for for loops.
  3. Alan Offer pointed out that f(*b[]) changes the array values.
  4. January 27, 2020. I found that the BC 1.06.95 command

    bc bigu stoltvialmm squareroot

    produced an error message:

    squareroot 667: Assignment of a void expression

    However on changing the order of files to

    bc squareroot bigu stoltvialmm

    there was no problem! This phenomenon is not present in bc 1.07.1.

    Also see Pádraig Brady's example.


Last modified February 3, 2020