0% found this document useful (0 votes)
50 views5 pages

UC2 Week 8 Topic: Basic Programming Ii Sub-Topic: Built-In Functions Writing Simple Basic Programs

The document discusses basic programming in BASIC, including examples of simple programs to calculate averages and solve quadratic equations. It also describes various built-in mathematical functions in BASIC like SQR, INT, COS, SIN, and LOG. Examples are provided to demonstrate how to use these functions in programming.

Uploaded by

Etta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views5 pages

UC2 Week 8 Topic: Basic Programming Ii Sub-Topic: Built-In Functions Writing Simple Basic Programs

The document discusses basic programming in BASIC, including examples of simple programs to calculate averages and solve quadratic equations. It also describes various built-in mathematical functions in BASIC like SQR, INT, COS, SIN, and LOG. Examples are provided to demonstrate how to use these functions in programming.

Uploaded by

Etta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

UC2 WEEK 8

Topic: BASIC PROGRAMMING II


Sub-Topic: Built-in Functions
WRITING SIMPLE BASIC PROGRAMS
Programming is best learnt by constant practice. We have use example to demonstrate how to write
computer programs.
Example 1
Program to find the average of six numbers
10 REM Program to find the average of six numbers
20 INPUT A, B, C, D, E, F
30 LET SUM = A + B + C + D + E + F
40 LET AVERAGE = SUM/6
50 PRINT AVERAGE
60 END

Example 2
Program to evaluate the roots of a quadratic equation.
Solution
10 REM Program to solve quadratic equation.
20 INPUT a, b, c
30 LET Root = SQR (b^2 – 4*a*c)
40 LET x1 = (–b + Root)/(2*a)
50 LET x2 = (–b – Root)/(2*a)
60 PRINT “Root are: x1 = ”, x1; “x2 = ”, x2
70 END

BASIC Built-in Functions

BASIC built-in functions are predefined functions that performs a wide range of operation. A function is
a structure that simplifies a complex operation into a single step. BASIC has a number of built-in
functions that greatly extends its capability. They include the following:
1. SQR Function: The SQR function calculates the square root of a number. The general form of the
function is SQR(X)

Example:

SQR(9) = 3

SQR(2) = 1.414214

2. INT Function: The INT function finds the greatest integer less than or equal to a number. The
general form of the function is INT(X)

Example

INT(15.46) = 15

INT(-15.46) = -16

INT(15.56) = 15

INT(-15.56) = -16

3. CINT Function: CINT means Integer Conversion. This function is used to convert a number into an
integer. It rounds off the number to the nearest integer value.

Example

CINT(15.46) = 15

CINT(-15.46) = -15

CINT(15.56) = 16

CINT(-15.56) = 16

4. Fix Function: This function truncates the number into an integer. The General form of the function
is FIX (X)

Example

FIX(15.46) = 15

FIX(-15.46) = -15

FIX(15.56) = 15

FIX(-15.56) = -15
5. ABS Function: ABS means absolute. It is used to find the absolute value of a number. Absolute
value of a number means the number without any sign. The general form of the function is ABS(X)

Example

ABS(+3.4) = 3.4

ABS(-3.4) = 3.4

6. RND Function: RND means random. RND is a special function that gives us a random number
between 0 and 1

Example

PRINT RND

PRIND RND

This program will print RND twice. Notice that you’ll get to numbers that appear to be unpredictable
and random. But, try running the program again. You’ll get the same random numbers.

7. COS, SIN, TAN, and ATN Function

The COS, SIN, TAN, and ATN trigonometric functions are used to find the Cosine, Sine, Tangent and
Arctangent of a particular numeric expression. The general form is:

COS(X)

SIN(X)
TAN(X)
ATN(X)

8. MODE Function: It means remainder. This function returns the remainder. The general form of the
function is X MOD Y

Example:

16 MOD 5 = 1

30 MOD 5 = 0

9. SGN Function: It means sign. This returns the sign of the input number in numeric value. The
general form of the function is SGN(X).

Examples

SGN(54) = 1

SGN(-54) = -1

SGN(0) = 0
10. EXP Function: It is used to find the natural exponent of x, where e = 2.718281828. the general form
of the function is EXP(X)

Example

EXP(4) = 54.59815

EXP(-5) = 6.737947E-03

11. LOG Function: This function returns the natural logarithm of a numeric expression (any positive
numeric expression). The syntax is LOG(X)

BASIC NOTATION

−b ± √ b 2−4 ac
a. = -B+-SQR(B^2-4*A*C)/2*A
2a
b. (x-y)/(x+y) = (X-Y)/(X+Y)

c. -ex+y – sin(x+ny) = EXP(X^2+Y)-SIN(X+N*Y)

d. b=1/4ac = B = 1/4*A*C

BASIC PROGRAM

1. Find the square root of numbers in a given range

10 REM program to find the square root of numbers

20 INPUT “Enter the first number of range”; A

30 INPUT “ENTER the last number of range”; B

40 FOR I = A TO B

50 PRINT “the square root of “; A; “is”; SQR(A)

60 NEXT I

70 END

2. Find the Sine of unknown values

10 REM Program to find the Sine of unknown value

20 INPUT “Enter the number”; A


30 LET S = SIN(A)

40 PRINT “The Sine of”; A; “is”; S

50 END

3. Plot Cosine Graph

10 REM Program to plot cosine graph

20 SCREEN 13

30 FOR X% = 0 TO 360

40 PSET (X%, (COS(X% * 0.017453) * 50) + 50), 15

50 NEXT X%

60 END

Video Links:

You might also like