Command Prompt for Windows




CALC Examples

Example 1:

Consider the following command line :-

CALC ? 1 + 1 > 1

The result of the above arithmetic expression 1 + 1 is 2. Since the output has been redirected, the result will be written to the file "1". However, if brackets were used around the expression, as follows :-

CALC ? ( 1 + 1 > 1 )

then the result of the above boolean expression (1 + 1 > 1) is the value 1 (ie. true), which will be display on the screen.

Example 2:

Consider the following command line :-

CALC ? ( "a string" == "a string" && "hello" != "world" )

The result of the above boolean expression is the value 1 (ie. true), which is displayed on the screen.

Example 3:

Calculate the cosine of 2.5 degrees :-

CALC ? COS( (2.5-INT(2.5/360)*360) * 3.14159265359 / 180.0 )

will display the value 0.999048221582.

Example 4:

Calculate the distance between the two points (1, 1) and (3, 4) :-

CALC ? SQR( POW(3-1, 2) + POW(4-1, 2) )

will display the value 3.60555127546

Example 5:

Consider the following batch file :-

@ECHO off
CLS
SET text=hello, world
STRSIZE %text%
CALC (80 - strsize) / 2
LOCATE %calc% 0
ECHO %text%

This program will clear the screen and display the text 'hello, world', centred on the first line.