QBASIC | Library FUNCTION Tutorial.


Start from Main page:>

In every programming language, there are prebuilt peace of code that are commonly used and are called library functions. These functions are like ready-made tools that programmers can use in their programs. The great thing about library functions is that they can be reused in different programs whenever we need them. We can use them over and over again as much as we want.

Now, let's take a look at what a library function is and how it is used. Here are a few examples:

Mathematical Library Functions:

Example: Square Root (SQR)
CLS
PRINT "Enter a number:"
INPUT num
result = SQR(num)
PRINT "Square Root:", result
END

Example: Absolute Value (ABS)
CLS
PRINT "Enter a number:"
INPUT num
result = ABS(num)
PRINT "Absolute Value:", result
END

Example: Integer Value (INT)
CLS
PRINT "Enter a number:"
INPUT num
result = INT(num)
PRINT "Integer Value:", result
END

Example: Modulus (MOD)
CLS
PRINT "Enter dividend:"
INPUT dividend
PRINT "Enter divisor:"
INPUT divisor
result = dividend MOD divisor
PRINT "Modulus:", result
END

Example: Sine (SIN)
CLS
PRINT "Enter an angle (in radians):"
INPUT angle
result = SIN(angle)
PRINT "Sine:", result
END

Example: Cosine (COS)
CLS
PRINT "Enter an angle (in radians):"
INPUT angle
result = COS(angle)
PRINT "Cosine:", result
END

Example: Tangent (TAN)
CLS
PRINT "Enter an angle (in radians):"
INPUT angle
result = TAN(angle)
PRINT "Tangent:", result
END

Example: Convert to Integer (CINT)
CLS
PRINT "Enter a decimal number:"
INPUT num
result = CINT(num)
PRINT "Converted to Integer:", result
END

Example: Sign Function (SGN)
CLS
PRINT "Enter a number:"
INPUT num
result = SGN(num)
PRINT "Sign:", result
END

Example: Exponential Function (EXP)
CLS
PRINT "Enter a number:"
INPUT num
result = EXP(num)
PRINT "Exponential:", result
END


 If you like this Please share with your friends, thanks.

Post a Comment

Previous Post Next Post