bc


So, I just discovered the Unix tool bc.  Given that I’m a Mac guy as much for the Unix as for anything else, this got me interested.

bc is a mathematical programming language and interactive calculator.  The latter is useful, sometimes I need a calculator, and for what I’m doing that instant, a terminal app is most appropriate.  bc fills that role well.

bc also is a C like programming language for mathematical operations.  I haven’t gotten deeply into it, but here’s a factorial function, with a simple recursive implementation.  

/*Factorial function in bc*/

define fact(x)

{

    if( x <= 1){

        return 1

    }else{

        return x * fact(x-1)

    }

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: