Basic Programming II
Basic Programming II
BUILT-IN FUNCTIONS
A function is an operation stored in or built in BASIC programming language, which when
issued performs a particular task.
A function may associate with one or more values as inputs and returns only a single value
as output.
BASIC has a number of built-in functions which greatly extend its capability.
1. SQR: the SQR function calculates the square root of a number. E.g.: SQR(9) is 3,
SQR(16) is 4.
Example:
10 REM CALCULATE SQUARE ROOT OF A NUMBER
20 LET N=100
30 PRINT SQR(N)
40 END
Example: Write a program to find the square root of 3a+2b, if a=2 and b=3.
10 REM CALCULATE THE SQUARE ROOT OF 3A+2B
20 READ A, B
30 DATA 2, 3
40 PRINT SQR(3*A+2*B)
50 END
2. INT: the function INT finds the greatest integer less than or equal to a number. It
discards the decimal part of positive numbers. E.g.: INT(2.7) is 2.
Example:
10 REM EVALUATING FUNCTIONS
20 LET N=6.25
30 PRINT INT(N)
40 END
3. ABS: the ABS function is used to find the absolute value of a number. Absolute value
of a number means the value itself without any sign.
Example:
10 REM FINDING ABSOLUTE VALUE
20 PRINT ABS(-2.8)
30 PRINT ABS(+3.5)
40 END
4. RND: the RND function is a function that gives a random number between 0 and 1.
Example:
10 CLS
20 PRINT RND
30 PRINT RND
5. COS, SIN, TAN, ATN: these functions will find the cosine, sine, tangent and
arctangent (inverse of tangent) of a value.
Example:
CONST PI=3.141593
PRINT COS(PI/4)
PRINT SIN(PI/3)
PRINT TAN(-PI/2)
PRINT ATN(TAN(-PI/2))
6. LOG: it finds the natural logarithm of a number.
Example:
PRINT LOG(28)
PRINT LOG(136)
7. EXP: it is used to calculate the exponential function (raising e to the power of any
value), where the value of e is 2.13
Example:
PRINT EXP(4)
PRINT EXP(-7)
8. MOD: MOD is means remainder. It is a function used to find the remainder when a
number is divided by another.
Example:
PRINT 15 MOD 4
PRINT 32 MOD 7
BASIC NOTATIONS
2
1. x= √
b −4 ac
2a
=SQR(B^2- 4*A*C)/2*A
x− y
2. x+ y
=(X-Y)/(X+Y)
3. ( a+ b ) +c ÷sin d
=(A+B) + C/SIN D
4. ex2+y – Sin (x +ny)
=EXP(X^2+Y) - (SIN(X+N*Y)
5. b=1/4ac
B=1/4*A*C