Are you looking for an essay on ‘BASIC Programming Language’ for class 9, 10, 11 and 12. Find paragraphs, long and short essays on ‘BASIC Programming Language’ especially written for school and college students.
Essay on BASIC Programming Language
Essay Contents:
- Essay on the Definition of BASIC Programming Language
- Essay on the Structure of BASIC Programs
- Essay on the Elements of BASIC Programming Language
- Essay on the Arithmetical Operation Using BASIC Programming Language
- Essay on the Data Input for BASIC Programming Language
- Essay on the Output—Information in BASIC Programming Language
- Essay on the Format-String Symbols for String Values in BASIC Programming Language
- Essay on the Format-String Symbols for Numeric Values in BASIC Programming Language
- Essay on the Commands Used in BASIC Programming Language
- Essay on the Program Control in BASIC Programming Language
- Essay on the Subroutines in BASIC Programming Language
- Essay on the Arrays Used in BASIC Programming Language
- Essay on the Library Functions in BASIC Programming Language
- Essay on the Definition of Function Used in BASIC Programming Language
Essay # 1. Definition of BASIC Programming Language:
BASIC, which is the acronym, a short form, of Beginner’s All Purpose Symbolic Instruction Code, is a high level language of immense popularity, which has all the nuances of different programming techniques. It was originally developed by John Keremy and Thomas Kurtz at Dartmouth College, in mid-1960s.
As newer versions started coming up, offering different facilities and with different syntax, the American National Standard Institute, popularly known as ANSI BASIC-which is provided in all the versions of BASIC.
What we will discuss here is the interpretive BASIC provided with MS DOS GWBASIC. this software provides the environment, when loaded for writing and running programs, with built-in editing facilities. To start BASIC, just enter the name of the file GWBASIC at the DOS prompt of A> or C> and press the Return Key.
The BASIC will be loaded by MS DOS, providing the BASIC environment, when the language interpreter takes over the command of the computer. To exit from the BASIC environment, just type SYSTEM and press return and you will see the DOS prompt again.
Incidentally, BASIC does not have any prompt like MS DOS, but it response with OK when waiting for your instruction, which is called Command-level. An OK means you can go ahead to do whatever you want, provided it is permitted under the language.
Essay # 2. The Structure of BASIC Programs:
There is a definite style of giving instructions in BASIC when writing programs, which are executed in what is called indirect mode. All the instructions, which you want to be executed automatically, one after another, are done in the indirect mode and to indicate this, a line number has to be given before each line, which can be any positive integer from 0 to 65,529.
Generally the line numbers are given in multiple of 10, starting with 10, as 10, 20, 30,… etc. This is done to provide scope for program modification, by entering instructions in between the existing lines without having to rewrite the whole thing with new line numbers.
In the direct-mode, any BASIC statement can be entered without the line number, but starting with an exclamation mark “?” and it will be executed immediately. However, all programs, are written for execution in indirect-mode.
The structure of a BASIC program, written in indirect mode, is as follows:
1. Each instruction forms a separate statement of execution.
2. Each statement begins with a line number, followed by a BASIC keyword—which are reserved words having special meaning, with predefined syntax. Hence, the syntax of a BASIC statement is n BASIC keyword where n stands for line number.
3. Each line number must be unique—no two lines can have the same number. Instructions are executed one by one as per the line numbers, starting with the lowest one; successive statements having increasing line numbers.
4. Normally only one statement can be written on a line with a distinct line number. However, if colon ( : ) is used as a separator, then more than one statement can be written on a line, without requiring another line number. But, the maximum number of characters, including blank spaces in a line can only be 255. The screen being 80 column wide, longer lines get wrapped around to the next line automatically and continues.
A BASIC statement is either executable or non-executable depending on the keyword used in the statement. The executable statements are basically program instructions, which are executed by BASIC, as per the instructions given. Before going into the actual statements or writing programs, you have to be familiar with various terms and concepts, which are specific to BASIC.
Essay # 3. Elements of BASIC Programming Language:
Character Set:
A character denotes any letter, numeric digit, normal punctuation marks or any other special printable character available in the keyboards, which are used to represent data.
The characters permitted in BASIC are:
A to Z, 0 to 9, +, -, =, *, /, \, ^, (,),;, „ ., $, <, >, “,’, %, !, &, ?, _, blank-space — that is 26 + 10 + 24 = 60 characters.
In BASIC, lower-case characters are automatically converted to upper-case characters, except when they are enclosed in double-quotation marks.
Constants:
Constants, are similar to the concept that you learnt in school—their values remain unchanged. BASIC provides for two types of constants, called numeric constants and string constants. Numerical quantities, 0 to 9 or combinations with or without decimal points and + or − signs, by themselves are numeric constants.
Large numbers can be represented in exponential form, which uses the powers of 10 as a multiplier—E or D is used in place of 10. For example, 6×108 is expressed as 6E8 or 6E+8. The exponent can be negative.
Any character or a series of them including a blank enclosed within the double quotation marks is called a string constant; the maximum length of a string being allowed is 255 characters. These are generally used for proper names. A string constant is also called a literal. The term, “Accountancy”, is a string constant.
Variables:
A variable is a data-name, or an identifier, which is used to store different values during processing of data. For example, you have used variables in algebraic equations in school like x, y, etc.
In BASIC, like constants, the variables are of two types called Numeric Variable and String Variable. The numeric-variables have numeric constants as their values, which takes up different constant values at different stages of execution.
The name of a numeric variable can be written using up to 40. Characters—letter, numbers, and decimal- point—but the first character must be a letter. For example, AMOUNT, A1, etc. can be used as names of numeric variables.
Likewise, the string-variables, which contain string constants as their values, can be named, however, the last character in the name of a string variable is a $ sign, like, NAMES – “Ashok Bagchi”; where NAMES is a string variable.
Whenever you use a numeric variable in a statement, make sure that it has a value assigned to it, otherwise by default it will have a zero value. Variables are created whenever any value is assigned to it by using the equality symbol. For example, BAT = 30.25 defines a numeric variable BAT and a value of 30.25 is assigned to it. Later on, the value of BAT may change during processing.
Whenever assigning values, you must remember to use the right type of constants for the right type of variables, or there will be a “Type mismatch”. For example, if you write BAT = “Ashok” it will be an error, because BAT is a numeric variable. Similarly, if you write BAT$ = 1200, it will also be an error and the interpreter will complain about it.
Essay # 4. Arithmetical Operation Using BASIC Programming Language:
If you are asked the answer of 8 + 4 x 2, and if you had done your home-work in school, you would say 16 and not 24—because the multiplication is done before addition, under the rule called BODMAS. Similarly, in BASIC, there is a distinct and different priority attached to each of the mathematical symbols used, called hierarchy of priority, which are, in order of priority, with 1 having highest priority —
1. ^ — Exponential or power symbol: 2^8 will by 28
2. – — Negation: changing the sign of a number.
3. * — Multiplication
3. / — Floating point division [normal division]
3. \ — Integer division: result is an integer
3. MOD — Modular division: gives the remainder
4. + — Addition
4. – — Subtraction
The operators which are at the same priority level, like + and − with priority 4, are executed from left to right if used in the same formula. The brackets ( ), which have to be used in pairs, are not an operator—their presence changes the order of priority; operators inside the bracket are executed first, under the same priority rule. For example, (8 + 4) * 2 = 24 and not 16, the + operator being within the bracket is executed first.
The mathematical operators are used to connect different numerical variables and or constants to form formula, which is also called an expression. In fact, an expression in BASIC means a constant, the value of a variable, or the result of evaluation of another expression.
For example, Y = X + Z*R is an expression. If X = 10, Z = 12, and R = 30, the expression after evaluation gives 370, which is then assigned to Y, making Y = 370. The value of the right side is assigned to the variable on the left side. As far as string variables are concerned, the + operator can be used to concatenate, to join, two strings. For example, if A$ = “My” and B$ = “Book”, then A$ + B$ would be equal to “My Book”.
When using mathematical operators, you must make the expression explicit, you know that 2A stands for 2 into A, but the computer does not. So, you will have to write it as 2 * A. You can obviously use only one operator between two variables, except the negation operator.
In a division, you cannot have the denominator as zero. Be careful to use the operators keeping in mind their priority, otherwise, you will end up with logical errors. You can use blank space between operators, etc. for better readability.
Essay # 5. Data Input for BASIC Programming Language:
Now that you know the importance of data, let us see how BASIC deals with input data. This data, whether it is stored in a file, or being entered by the user on being prompted by the computer during program execution, is assigned to a variable with a distinct name identifying it.
Once a variable with a name is thus created, during execution a definite storage location with a definite size in the main memory is allotted to it and thereafter, we manipulate the data, not by the address where it is stored but by the name of the variable to which it is attached.
A variable is created by using a reserved word LET, whose syntax is:
LET variable-name = a value
The value being provided by a constant, another variable with a value, or by evaluation of an expression like say, C + 10 * D, which evaluates to 32 with C and D being equal to 2 and 3 respectively.
The equality sign here means assigning-the-value on its right side to the variable on its left side.
The type of variable must match with the value assigned to it, otherwise an error of “Type mismatch” will occur—you cannot assign a numeric value to a string variable and vice versa.
Because the equality sign is used here for assigning a value, we can have an expression like A = A + 1, or A = A + B, where A and B are variables, which is not valid in algebra, because = sign there means equality only. When we write, A = A + 1, what it actually means that: add one to the existing value of A and assign it to A as the new value. So, if previously A was 15, now it will become 16.
In modern BASIC, the word LET need not be used at all. Incidentally, with LET statement, only one variable can be created at a time—you cannot have LET A, B = 10, 15.
Variables can also be created by two other statements, which also assign values simultaneously to one or more variables; one of them being READ .. DATA.
The syntax is:
The DATA statement provides the values for the variables specified in the READ statement, their being one-to-one correspondence, which means, the first value [constant] is assigned to the first variable, the second value is assigned to the second variable, and so on. The values for the corresponding variables must be of the same type to avoid “Type mismatch”.
The string constants given in the DATA statement must be enclosed in quotation marks if it contains comma, or blank spaces at the beginning or end; otherwise the double-quotes are not required.
If the number of variables specified in the READ statement is more than the number of constants in the DATA statement, in each case separated by commas, then “Out of data” error occurs during execution. If the number of variables is less, the extra data is ignored.
You have to treat the variables in the READ statement and the constants in the DATA statement as two continuous lists, irrespective of the number of lines used to write them separately and then you will not make any mistake in assigning correct values to variables.
Let us take a few example to demonstrate this aspect.
Example 1:
10 READ A, B, C, D$, E$, F, G
90 DATA 6, -8.2, Idiot, Smart, 100.632, Sporting, 37, 82.65
On execution, A = 6; B = -8.2; C—Type mismatch, a string “Idiot” is assigned to a numeric variable; D$ = “Smart”; E$—Type mismatch, a numeric constant 100.632 is assigned to a string variable; F—Type mismatch, a string constant “Sporting” is assigned to a numeric variable; G = 37. The numeric constant 82.65 is ignored. Had 37 and 82.65 were omitted, it would have said “Out of data”.
Example 2:
The above READ statement of line 10 could also be written as shown below having the same effect:
10 READ A,B,C
20 READ D$
30 READ E$
40 READ F,G
Similarly, the DATA statement can also be written in different lines, as long as the order remains same. The DATA statement can be written anywhere in the program, but usually, it is written at the end of the program for better readability. As you can see, the combination of READ and DATA is used for batch processing of large number of data already entered. The READ is an executable statement and DATA is a non-executable statement.
The sequence of the READ and DATA combinations get altered, when another statement called RESTORE is used, whose syntax is:
RESTORE [line-number]
the square bracket indicates that the line-number is optional, it may or may not be used, but with different effect. If the line number is not specified, RESTORE revives all DATA statements which have already been assigned to different variables and makes these available to the next READ statements again.
Essay # 6. Output—Information in BASIC Programming Language:
Since the technology of typewriting was known when early computers were developed and the technology of Cathode Ray Tube [CRT] used in VDU was not known, everything that such computers produced were printed output, with Print commands. Unfortunately, when the display units came into widespread use, the old convention continued, and so the word PRINT is still used in BASIC to mean display.
Its syntax is:
PRINT list of expressions
The list of expression is a list of numeric/string constants, variables, or numeric expressions, each separated by commas or semi-colons. Any string constant has to be enclosed in double-quotation marks.
During execution, the PRINT causes the list of expressions, variables and formulas replaced by their respective values, and displayed on the screen in a format depending on whether commas or semi-colons have been used to separate the items in the list of expression.
If comma is used as a separator, then the 80-column display line is divided into zones of 14 characters each, and each item is displayed serially at the beginning of each zone—so five items are displayed on a line, continuing to next line, if required.
When semi-colons are used as a separator, the items are displayed immediate next to each other under the following conditions. Numbers are always followed by a blank space. Positive numbers are preceded by a blank space, whereas negative numbers have negative sign before them. Let us look at a display.
Example 3:
To demonstrate the effect of comma and semi-colon on formatting.
10 READ A, B, C, D, E, and F
20 PRINT A; B; C; D; E; F
30 PRINT A, B, QD, E, F
80 DATA 1234444,5678888, 9012222, 3456666, 7891111, 2345555
The line 20 prints the output as—
1234444 5678888 9012222 3456666 7891111 2345555
keeping two blank spaces between the numbers; with negative numbers, one space is taken up by the (-) sign.
The output of line 30 becomes:
1234444 5678888 9012222 3456666 7891111
2345555
There being 7 blank spaces between the digits. In each case one blank space’ is left at the beginning of the line for the (-) sign, if any.
As you can appreciate, the PRINT statement offers only a limited scope for displaying outputs in a well formatted manner. Hence, there is another statement which provides the facilities to display output in neat tabular forms, especially with numerical values. The syntax is—
Print Using Format-String; List-of-Expression:
The format string provides the formatting set up to be adopted when displaying values, constants, etc. The symbols used are different for string and numeric variables.
Essay # 7. Format-String Symbols for String Values in BASIC Programming Language:
! : a! Mark in the format-string specifies that only the first character of the string constants of the list-of-expression is to be displayed
\ n spaces \ : This specifies that (n+2) characters of each string is to be displayed. If n = 0, only two characters are shown. If the length of the string is less than the number of characters to be displayed, then blank spaces are used to fill up the spaces.
&: It specifies variable length string, that is, the displayed string is identical with the original string.
Example 4:
10 A$ = “Personal”: B$ = “Computer”
Essay # 8. Format-String Symbols for Numeric Values in BASIC Programming Language:
#: It specifies the number of digit positions to be displayed. If the number of digit-position is more than the actual digits to be displayed, then the numbers are right justified. A decimal position is displayed using a period (.).
**: It is used at the beginning of the format-string to fill up the leading blank spaces with this symbol. It also specifies two digit positions.
$$: it causes a $ sign to be displayed at the immediate left of the displayed number. It also specifies two digit position, one of which is $. It cannot be used with exponential format. For negative numbers, the (-) sign has to be displayed at end.
**$: Combines the effect of the above two symbols. It represents 3 digit positions, one of which is $.
,: Used on the left of the decimal point causes a comma to be displayed to the left of every third digit, which are at the left of the decimal point.
^^^^: displays values in exponential form as E+nn or D+nn [double-precision] Any decimal point position may be specified. The significant digits are left justified. Unless a leading + sign or a trailing + or – sign is specified, one digit position is used to the left of the decimal point to display a space or a sign.
+: Can be used at the beginning or end of the format string. It causes the sign of the number to be displayed before or after the number.
-: When used at the end of a format-string, causes negative numbers to displayed with a trailing minus sign.
_ : The underscore causes next character to be displayed as it is.
If the number to be displayed is larger than the specified numerical field, a % sign is displayed in front of the number. It is also displayed when rounding off is done for a number which exceed the field. If the number of digit field is specified as 24, an “Illegal function call” is displayed; as an error. Let us use a simple two line program with numerical values of different width, to see the effect of using different symbols in PRINT USING.
Example 5:
Numerical Value display with Print Using “#” as digit-position and comma separator:
The output is:
12.34 123.451234.57%12345.68
The % sign in case of variable D indicates overflow taken care of by rounding. No gap is provided between the displays of different values.
With semi-colon separators the output is same as before:
20 PRINT USING “####.##”;A;B;C;D
12.34 123.451234.57%12345.68
To get the output printed by a printer, simply use a L before the word PRINT and PRINT USING, making them LPRINT and LPRINT USING—all other things remaining same. BASIC assumes that you are using a 80 column printer.
Essay # 9. Commands Used in BASIC Programming Language:
In BASIC, commands and statements are both executable statements—the former being at command level, with no line numbers or even “?” before them.
Some of the commands are:
RUN [filename]:
Executes the program residing in memory. When the filename is specified, it loads and runs the file. It closes all previous open files.
RUN [line-number]:
Executes the program residing in memory, but starting with the line number specified.
SAVE filename [,a]:
Saves the program in the memory to the filename specified in compressed binary format. When [,a] is used, it is saved in ASCII format, which can be seen with the Type command of MS DOS.
SAVE filename [,p]:
Saves the file in encoded binary format, which cannot be seen. An attempt to LIST the program will cause “Illegal function call”. The SAVE command assigns .bas extension to files saved, unless a different extension is given. If the filename is followed by [,a] or [,p], then it is to be enclosed in double- quotation mark. An existing file, with the same name is over written without any warning.
LOAD filename:
Loads a program from disk to memory and assumes .bas as the default file extension. It clears memory of old program and closes all files.
LIST [line-number] [-line-number] [,filename] — displays the program in memory when used singly, scrolling the lines if required. The line-numbers specified are used as a range, to which the display is restricted. A different filename can be specified to load and display.
LIST [line-number-], [,filename] — displays, starting with the line-number specified; others as before.
NEW deletes the program currently in memory.
Essay # 10. Program Control in BASIC Programming Language:
The execution of a program, as you know by now, always proceeds in a sequence, one after another, unless some imposed conditions or instructions cause it to deviate from the normal sequential course. In BASIC there are a number of commands which allow you to control the flow of program.
a. Unconditional Branching:
When the execution of instructions, deviating from normal sequence, moves to a different location it is called branching. In unconditional branching, the control definitely shifts without waiting for any condition to be fulfilled. In fact, no condition is provided for evaluation at all.
The command for unconditional branching, which is also used for uncontrolled looping, is GOTO n, where n is a valid line number in the program. On reaching the GOTO statement, the execution unconditionally branches off to the line number provided in the command and there from the execution continues. Use of GOTO is strongly dis-favoured in structured programming.
Example 6:
Example of GOTO
As soon as line 40 is reached, it is again sent back to line 10, a case of unlimited, uncontrolled looping. To get out of this program, you will have to use Break or Cntrl-Break key.
Relational Operators:
These operators are used to compare two values, the result being given as True [-1] or False [0]. Naturally, these operators are extensively used as conditions in decision making.
The operators are:
These operators are also used for string comparisons, where the equivalent ASCII values are compared; like B is greater than A.
b. Conditional Branching:
There are two sets of commands providing for conditional branching—where branching takes place only on fulfillment or non-fulfillment of certain condition. One of the command is called IF – THEN – ELSE, whose syntax is:
IF expression [,] THEN statement [,] [ELSE statement]
IF expression [,] GOTO line-number [[,] ELSE statement]
In the above statements, the “expression” is evaluated, and if found true a non-zero value is returned and the “statement” after THEN is executed. Otherwise, the statement after ELSE is executed, that is, when the “expression” is found to be false giving a zero value. In the second variation, instead of executing a statement, the control shifts to the line number specified, if the outcome of evaluation is true.
This conditional branching statement can be nested, that is, you can have one set of IF-THEN-ELSE statement within another set of IF-THEN-ELSE statement. If the statements do not contain same number of ELSEs and THENs, each ELSE is matched with the closest unmatched THEN.
For example, in the following program, there is no matching ELSEs and THENs and so we get different output under different conditions, which are different from our expectations in some cases. It will not print A <> C when A <> B.
Example 7:
The following program demonstrates a typical case of using a string variable to get user’s response and act accordingly. At line 70, it either ends execution or goes back to line 30 and continues.
Example 8:
The above was a case of spaghetti programming. The same output can be achieved in a simpler way in the following program:
c. Conditional Looping:
Often, it becomes necessary to execute a series of one or more sequences repeatedly for a specified number of times, as will be shown later in different examples.
Such type of repetition is called controlled looping and BASIC provides for controlled looping operation by FOR-NEXT statement, whose syntax is:
FOR variable = x TO y [STEP z]
Statements to be repeated……….
NEXT [variable]
The “variable” is used as a counter to control the loop. An initial value x is assigned to the “variable”, which is compared with the maximum limit given by y, if the value of x is not greater than the value of y, execution starts from just after the FOR statement and continues till the NEXT statement is encountered.
At that stage the value of x is incremented by adding the value of z to it and again the new value of x is compared with the value of y—if x is not greater than y, the sequence is again executed—the execution stops when the value of x becomes greater than the value of y.
This is the case when the value of z is positive. If no value is provided for z, it is taken as 1, called the default value. If the increment is positive, the value of y must be greater than the value of x to start with. If the value of z is negative, the condition checked is whether x is lower than y or not— if not lower, the execution continues. The examples given below clearly show this aspect.
The initial value of X is greater than the maximum value, so the loop is not executed even once. Control shifts from line 20 to line 50 directly.
Example 9:
The value of X changes from 1 to 0,-1,-2,-3,-4 and then the loop is exited, so it is executed 6 times.
d. Multiple Branching:
BASIC also provides a statement for multiple branching, where, depending on the value of a variable, execution starts from different line numbers.
The syntax is:
ON n GOTO line [,line] …
Where n is a numeric expression which is converted to an integer if it is not and then depending on its value, which must be between 0 and 255, the control shifts to the appropriate line. For example, if you use ON n GOTO 100,200, 300, and n evaluates to 1 control will go to line 100; with n = 3, the control will go to line 300.
If the value of n is zero or greater than the number of items in the list, but less than or equal to 255, the program continues to execute with the next statement, totally ignoring the ON … statement.
Example 10:
What will be the output of this program?
(a) 100 (b) 100 and 300 (c) Goes into an infinite loop during second 300 iteration (d) Syntax error in statement 20 because the same line is used more than once.
During the first cycle of the loop, I becomes 1 and so, as per line 20, control shifts to line 100, which displays 100. By going to line 100, the control is now out of FOR-NEXT loop, hence the line 300 is executed in the normal course, giving 300.
Essay # 11. Subroutines in BASIC Programming Language:
Subroutines are small program routines carrying out a particular operation and are used exclusively for repetitive jobs. For example, you may want to compute the area of a rectangle frequently. You can then treat the set of instructions as a subroutine and use it merely by using GOSUB line. Where line is the first line of the required subroutine.
The last line in a subroutine is RETURN, which causes the control to return to the next line of the GOSUB line which called it.
For example:
Example 11:
A demonstration of GOSUB 10 GOSUB
There can be several RETURN statements in a subroutine, each preceded by some conditions; the first RETURN encountered will cause it to return to the main program always.
You can use subroutines also as:
ON n GOSUB line [,line] …
It is identical to multi-branching, the difference being that it comes back on completion of execution.
Essay # 12. Arrays Used in BASIC Programming Language:
An array is a group of identical items which are represented by a single identifier with an index, which is used to access the different items contained in the array. Let us say we have four number of variables as 12, 62, 74, and 93 respectively. To use these values we will have to assign them to four variables, which have to be named, say, as x1= 12, x2 = 62, x3 = 74, and x4 = 93.
Alternately, we can define an array as x (n), where x is the name of the array and n is the subscript or index. So x(1) will represent 12, x(2) will be 62 and so on. Imagine a case where 100 such variables have to be used. Hence, arrays are extremely useful when large but similar items are concerned—you can have an array of numerical values or string values; both cannot be mixed up.
An array with a single index is called a single dimensional array. We can also have multi-dimensional arrays, the most common one being two-dimensional array, which is represented by two indices as array (m, n) and which is basically a representation of a table; where m contains the number of rows and n represents the number of columns.
The individual items are called elements of an array. In case of a string array, the name has to be suffixed with a $ sign.
In BASIC, the dimensions of an array is defined as:
DIM variable (subscript) [,variable(subscript)] …
where variable is the name of the array, subscript is naturally an integer representing the size of the array. Without a DIM statement, the maximum elements in an array can be 10 only by default. If the value of the subscript used is more than the default value or the range specified, an error is reported as “Subscript out of range”.
The default minimum value of subscript is 0, that is array (0) represents the first element. However, by using OPTION BASE 1, it can be changed from 0 to 1.
Example 12:
What is the output of this program?
This forms a two-dimensional array up to line 40 as:
Essay # 13. Library Functions in BASIC Programming Language:
BASIC provides a number of library functions, which are basically small programs, which can be used by writing their names with appropriate arguments.
Some of these are:
ABS(x): Gives the absolute value of a numeric expression, which is always positive or zero.
CINT(x): It converts x to an integer by rounding off the fraction. X can have a value between -32768 and 32767. Otherwise it overflows.
INT(x): It returns the integer portion of x.
SQR(x): It returns the square root of x.
LOG(x): Gives the logarithmic value of x with base e [natural].
VAL(x$): It gives the numerical equivalent value of x$, which has to be numerical.
SPC (n): It skips n spaces in a PRINT statement, where n = 0 to 255.
SGN(x): It returns the sign of x. If x is positive, the value returned is 1, 0 if x is 0, and -1 if x is negative.
RND[(x)]: It returns a random number with a value between 0 and 1. The return value is affected by the value of x. But if x is same, the values returned are also same.
Example 13:
Demonstration of some Functions:
Essay # 14. Definition of Function Used in BASIC Programming Language:
In BASIC you can define a function and then use it wherever needed.
The syntax is:
DEF FNname(arguments) expression
A name preceded by FN becomes the function, the arguments contain the name of the variables used in the expression and the expression provides interconnection of variables using mathematical operators.
For example:
The output of line 30 will be 773, which will be assigned to the variable result. In line 30, in the function name total, the expression of line 10 is used with x being replaced by a’s value of 2 and y being replaced by b’s value of 6.
BASIC also provides many other facilities and functions, including those for drawing graphical images and playing music. BASIC also has file handling facilities for sequential and random files.