Beginner's Programming Tutorial in QBasic

(Kiana) #1

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:


(^12)
(^34)
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:


(^1212)


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)

Free download pdf