Chapter No-4 "ARRAYS"

“ARRAYS”


Q:-WHAT IS AN ARRAY? WRITE DOWN A DETAILED NOTE ON ONE DIMENSIONAL AND TWO DIMENSIONAL ARRAYS?

ANS:-ARRAYS:-An array can be defined as “a sub scripted variable that has upper and lower bounds as its ending and starting positions and that sub scripted value may range between these two bounds, is called an array”. Types of arrays:- An array can be categorized into two types on the basis of these rows and columns. These types are given one by one below: One dimensional array: A sub scripted variable in which a single variable is used to represent the subscripts of the array and ranges between the lower and upper bounds of the array is called one-dimensional array. An example of such arrays in the real life may be a matrix consisting of rows or columns only.Two dimensional arrays:- A Two dimensional array consist of two subscripts in which ,the first represents the number of rows between the lower and upper bounds of row values and the second represents the number of columns between the lower and upper bounds of columns values. An example of such array is the two dimensional matrix which has two or more than two rows and two or more than two columns. Such an arrays can be diagrammatically shown as


10th   5

Q:-Why do we use (DIM) statement? If omitted? What will happen? Write down the detailed note on its use?

Ans:-if we want to declare an array then it is called DIM statement. With DIM statement we can also declare two dimensional arrays. Two dimensional arrays, which has two subscripts to identify each element of the array. eg A(3,2) SYNTAX:- For single dimensional array[Line no]DIM [variable (subscripts)], {variable (subscripts)} For double dimensional array [Line no]DIM [variable (subscripts, subscript)] EXAMPLE:- 10 DIM AR (90) These statements will create a single dimension array in memory with 90 subscripts. 20 DIM NAME$ (26), R NO (26), CLASS (26) These statements will create three single dimension arrays in memory each with 26 subscripts. 30 DIM TBL (10, 10) These statements will crate a double dimension array in memory each with 100 subscripts. These array elements are denoted like. TBL (2, 5), TAB (5, 3).
PROGRAM: – Now we make a program to learn the use of arrays.This program will count down the values from 25 to 5 with interval of 5 and then count up from 5 to 25 with same interval.
10 DIM A (5) 20 FOR 1= 1 TO 5 30 READ A (1) 40 NEXT 1 50 DATA 5,10,15,20,25 60 FOR 1= 5 TO 1 STEP -1 70 PRINT A (1) 80 NEXT 90 FOR F= 1 TO 5 100 PRINT A (F) 110 NEXT 1
PROGRAM: – This program is used to find the smallest number. 10 DIM K (100) 20 INPUT”HOW MANY NUMBER YOU WANT TO ENTER”;N 30 FOR 1= 1 TO N 40 INPUT K (1) 50 NEXT 1 60 KK= K (1) 70 FOR J= 2 TO N 80 IF KK>K (J) THEN KK= K (J) 90 NEXT J 100 PRINT KK 110 END

Chapter- 5 “Subprograms”


Subprograms:- A subprogram is a set of statements which are written once in the program and used or called many times in different places of program. Basic language offers two types of sub programs. 1:-subroutines subprograms 2:-functions Subprograms

Functions Subprograms: – Functions are those sub programs which are used to replace simple process such as calculating the square of a number, finding out the natural logarithm of a number and so on.Subroutines subprograms: – Subprogram which are used to do complex programming operations like calculating the roots of a quadratic equation, solving a matrix and soon.


What is the purpose of intrinsic functions? Why do we use them? Explain with suitable examples the different types of intrinsic functions.

Purpose of intrinsic: – They perform the most basic operations like calculating the square root, sine, cosine, language of angles and so on. Why do we use them: – When we want to solve the most basic operations like calculating the square root, sine, cosine,language of angles and so on then we use intrinsic functions. Types of intrinsic functions: – Then are categorized follows:-1. Numeric function: – The number of built-in functions which can be used for mathematical calculations. These functions return a number as their results.They are:-• Trigonometric functions:- Functions purpose Sin(X) Calculates the sine of X. Cos(X) Calculates the cosine of X.Tan(X) Calculates the tangent of X.Atn(X) Calculates the tangent inverse of X.• Arithmetic functions:- Functions purpose SQR(X) Calculates the square root of a given number. LOG(X) Calculates the natural logarithm of X.EXP(X) Calculates the exponential value of X. 2. String Functions:- The number of built-in functions which can be used for manipulations of string data. These functions return string and numeric values as their result. They are:- Functions purpose LEFT$(String,n) Selects the left most n characters of the given string. If n is greater then the number of characters Contained in the string, the entire string will be printed.RIGHT$(String,n) Selects the right most n character of the given string.3. String$ functions:- This string functions is used to repeatedly print out a character specified by the given ASCII number to the function STRING$. This functions has the following general form:STRING$(N,M).Exp:- 60 PRINT STRING$(3,67) 4. Time$ functions:- The TIME$ is a built-in functions in BASIC which is related with system time. It is used to show the current time or used to set the new time of the system. Exp:- 10 PRINT TIME$ and 20 TIME$ =”16:00:00” 5. Date$ functions:- Like time$ functions Date$ functions is used to display the current date, or set the new date of the system. The general syntax as:- Line DATE$. Exp:- 10 DATE$ =”03-07-2001” 6. ASC functions:- It is the inverse of CHR $ function, which returns corresponding character for a given ASCII value, because it returns the ASCII code for a given character. Its general form is : ASC (X$) 10 PRINT ASC (“ABC”). 7. LEN Function:- This function is used to print the total number of characters contained in the string. It has the general from like. LEN(X$)LEN (“”) Will print 0 where LEN (“Muhammad Naveed Ahmad”). 8. VAL function:-This function is used to return to return the numeric value of the given string argument in a string of numbers enclosed in the double quotation. It must be noted that the string must be the combination of number. Its general form. VAL(X$) Exp:- A$= “852772” 9. OCT$ function:- This functions is used to calculate the equivalent of a decimal number in the octal number system. The general form: OCT$(Decimal Number). 10. HEX$ function:- That is used to calculate the Hexadecimal equivalent of a number which is in the decimal number system. The general form: HEX$(Decimal Number).

]]>

admin

Leave a Reply

Your email address will not be published. Required fields are marked *