Home Previous section Next section

Mathematics functions


QBasic provides several functions to do mathematical calculations. A few of them are discussed here.


SQR

Use SQR to find the "square root" of a number.

    PRINT SQR(1)
    PRINT SQR(4)
    PRINT SQR(9)
    PRINT SQR(16)
    PRINT SQR(25)
Output:
    1
    2
    3
    4
    5

ABS

ABS returns the absolute value of a number. In other words, ABS converts a negative number to a positive number (if you pass a positive number, ABS does nothing).
    PRINT ABS(12)
    PRINT ABS(-12)
Output:
    12
    12

COS, SIN, TAN, and ATN

You can do the following trigonometric functions in QBasic:
    COS (Cosine)
    SIN (Sine)
    TAN (Tangent)
    ATN (Arctangent, inverse of TAN)
Example:
    CONST PI = 3.141593

    PRINT COS(PI / 4)
    PRINT SIN(PI / 3)
    PRINT TAN(-PI / 2)
    PRINT ATN(TAN(-PI / 2))
Output:
    .7071067
    .8660254
    6137956
    1.570796 
    (Same as PI / 2)

Next section


Feel free to distribute this tutorial, upload it to your website, link to it from your site, etc.

http://www.geocities.com/progsharehouse/qbtutor
Mirror: http://development.freeservers.com/qbtutor