CSC 102 Materials
CSC 102 Materials
CSC 102 Materials
08069018655)
DOWNLOADED FROM FUTABASE.COM
A TUTORIAL GUIDE
TO
CSC 102
BALOGUN, T. R
(a.k.a. B. PROGRAMMER)
COURSE OUTLINE
1
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
INTRODUCTION TO GENERAL COMPUTING
What is Computer?
The basic function of the computer can be represented as in figure 1.1 below
INPUT PROCESS OUTPUT
(1) Input: this is the entry point to a computer where data is fed into it
for processing, i.e. computer accepts input data
(2) Process: this is the operation of converting data (raw fact) read into
the computer into a finished and meaningful product (information) i.e.
a program or instruction in execution
(3) Output: this is the terminal point where information is being
produced i.e. computer generates information as output.
The benefit derived from the computer can be attributed to the following:
2
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Accuracy: the result produced from the computer is reliable as long
as the input is entered correctly
Vast storage capability: computer can store large data, information,
and instruction in a small-size memory which has enough/very large
storage location or places.
Economically: computer is very cheap to buy and can perform tasks
that would not otherwise be feasible or cost effective by other system
or machines
Versatility: computer can be used at a very wide range of application
such as engineering, science, technology, government etc.
Durability: computer can work for hours, days, weeks, months, years
non-stop without getting tired.
Types of Computer
Basically there are two types of computer namely; analogue computer and
digital computer. The comparison between the two is hereby presented in a
tabular form below;
3
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Represent physical or mathematical Represent numbers, letters, or
quantities in a continuous form. symbols in a discrete or
discontinuous form.
Mostly used as special- purpose Mostly used as a general device.
device.
When a computer makes use of both analogue and digital components and
techniques; it is called HYBRID COMPUTER. Such a computer requires
Analogue-to-Digital and Digital-to- Analogue converters; which would make
analogue data acceptable to a digital computer & vice versa.
4
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
OUTPUT UNIT: provides the medium by which the results of the
computer operations on input data are transmitted to the user. It
retrieves the information in computer readable form e.g. printers,
computer monitor, speaker etc.
AUXILIARY STORAGE: is a storage unit of larger capacity than
the main memory, for external (off-line) storage of data and
programme in readable form. Unlike the main memory, it is
non-volatile and thus provides a means of permanent storage of
information to be processed by the computer e.g. floppy diskette
drive, magnetic tape drive, magnetic disk drive, hard disk drive,
CDROM, flash drive, memory card etc. It is also known as Back-
up storage.
2. Central Processing Unit: This is the heart & central controller of all
activities of a computer. It consists of main memory, Control unit,
Arithmetic Logic Unit (ALU).
o Main memory: This is known as memory unit or primary
memory which serves as the brain of the computer that
provides temporary storage medium for input data of
programme. Before the computer can solve any problem,
all other related (data and instructions) must be loaded
into the memory unit. This comprises RAM and ROM.
o RAM- Random Access Memory, this is a volatile memory
that can hold data and instruction temporarily, data can
easily be lost if there is power interruption.
o ROM- This is a non-editable memory whose contents
cannot be change but can only be read i.e. it allows solely
read from but disallow written to its contents.
Control unit: This is main controller of activities of the
computer system. It selects relevant instruction from the stored
program(main memory) and interprets them, coordinates the
flow of data and program from the entry point of input, through
the memory for storage, to the ALU for execution and finally to
the output terminal.
Arithmetic Logic Unit (ALU): is the circuitry system for
performing both the arithmetic and logical operations on data
and program.
5
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
The computer software subsystem is a collection of all program
modules that are required by a computer system, to determine what the
computer does and how to do it. Unlike the computer hardware, it cant be
seen and touched; It can broadly be divided into 2 categories viz: SYSTEM
SOFTWARE and APPLICATION SOFTWARE.
6
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
also be viewed as an interface between the Source program and
the Object program i.e.
7
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
APPLICATION SYSTEM: These are set of programs that develop
basically with the intent of providing solution to different users programs or
to perform certain task. There are 2 categories of this software.
8
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
What is a program?
What is programming?
Who is a Programmer?
Low-level language
9
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
This is a 1st form of language developed basically for the computer
system. There are 2 types of low-level language viz:
Machine Language: This is a computer-understandable
language developed mainly for the operation of the
underlying hardware of a computer system. Instruction
written in machine language consists of series of binary
format code (bits), which does not require translator for its
execution, so there is fast execution. Programming with this
language is highly time-consuming, tedious and the most
error prone process.
10
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
2. MAINTAINABILITY: It must be easy to change, modify and
maintain.
3. EFFICIENCY: It must be fast in execution and be able to occupy
less memory space in term of storage.
4. RELABILITY: It must be able to produce expected result and
never crash.
5. PORTABILITY: It must be machine independent and must be
able to transfer from one machine (computer) to another.
6. DOCUMENTATIONABILITY: It must be easy to document or
keep for future use or further program
7. USABILITY: It must be useful for its purpose.
8. FRIENDLINESS: It must be user-friendly.
9. INTERACTIVITY: It must be interactive for user.
10. SIMPLICITY: It must enable the programmer to state a
computational solution to specific problem in a notation which
is both formal and human intelligible.
11
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
COMPILATION, DEBUGGING, AND TEST-RUNNING: This involves
the process of key-in the source code into the computer using
appropriate text-editor or IDE(Integrated Development
Environment) of the selected language, converting the source code
into computer-understandable code, during which there may be
errors (syntax error)found in the program, which requires
correction by fixing out the error and change it to the correct
syntax for the program to perfectly execute, finally, using various
values to test the correctness of the program as it is being
executed.
DOCUMENTATION:- There is need for keeping record of all the detail
description of every method/procedure used in solving the program, as
well as explanation on how the program function and uses.
Consequently, good documentation gives room for continuity and
maintainability.
Syntax error
Semantic error
1. SYNTAX ERROR
2. SEMANTIC ERROR
12
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
BASIC STEPS OF DEBUGGING
ALGORITHM DESIGN
WHAT IS AN ALGORITHM?
COMPONENTS OF ALGORITHM
I. SEQUENCE
II. SELECTION and,
III. ITERATION
SEQUENCE: This involves specification of steps of statements or
methods in a specific order i.e. every step of methods is written
in order they will be executed.
SELECTION: this involves specifying step of methods or
instruction by making decision based on condition that must be
satisfied, i.e. execution of set of instruction will be based on
making some choices/a choice from various options available.
ITERATION: This means repetition or looping, which refers to
repeating the flow of execution of set of statement for a specific
number of times or based on specific condition.
13
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
TWO WAYS OF DESIGNING ON ALGORITHM
I. PSEUDOCODE
II. FLOWCHART
PSEUDOCODE: This is an English-like representation of an
algorithm. Pseudocode cannot actually run on computer
because it is not an actual computer programming language,
rather it merely provide a convenient method that will assist
programmer to think out a program before attempting to write
it in a particular programming language.
EXAMPLES:
Step 5: exit.
Area = r2
Step 5: Stop
A=1/2bh
Step 1: Obtain value for base i.e. b
Step2: Obtain value for height i.e. h
Step 3: Multiply base, height, and half i.e. Set A=1/2*b*h
14
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Step 4: Print A
Step 5: Stop
I. Systems flowchart
II. Program flowchart
15
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Symbols used in flowcharting involve:
16
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
7. INITIALIZATION SYMBOL: Optionally used to denote the
parameters initialization
EXAMPLES:
START
ENTER a,b
C=a+b
Print c
STOP
Start
r 2
2. Design a flowchart to find the area of a circle A =
Pie= 3.142
Read r
A = pie*r^2
Print A
17
stop
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Input b, h
A=1/2*b*h
Print A
Stop
Start
Read A, B
No
Is A > B?
Yes
Print B
Print A
18
Stop
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Start
Count = 1, Sum = 0
Yes
Stop
19
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
WHAT IS BASIC?
20
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Version of BASIC language: Microsoft BASIC, Burmese BASIC,
Extended BASIC, Cassette BASIC, MFBASIC, Small BASIC, GW-BASIC,
Q-BASIC, etc. they all features in common but the systematic difference
between them are associated with hardware on which they are designed
to be used.
I. Numbers/digits (0-9)
II. Alphabets/letters (A-Z, a-z)
III. Decimal point (.)
IV. Blank character
V. Grouping characters e.g. colon, semi-colon, comma, single and
double quotes/apostrophe, and parenthesis.
VI. Arithmetic operators e.g.=,+,*,-,/,^,\
VII. Comparison operators e.g. =,<,>,<=,>=,<>
VIII. Underscore (_)
Data types refer to the type of value that a particular data represent.
Data in BASIC can be classified into two types:
21
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
c. NUMERICAL CONSTANT: are static value(s) that BASIC
interpreter uses during program execution, which may either be
positive or negative numbers.
What is a variable?
22
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
What is a constant?
1. Length
2. Breadth
3. A102
4. Sum2
5. Volume_Of_Sphere
23
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
OPERATOR MEANING ALGEBRAIC BASIC
EXPRESSION EXPRESSION
+ Addition a+b a+b
- Subtraction a-b a-b
* Multiplication a*b a*b
/ Division a/b a/b
\ Integer division a/b a\b
^ Exponentiation Ab A^b
= Assignment A = b+c A = b+c
NOTE: Expression within parenthesis, function are evaluated first before any
other operation is carried out.
EXAMPLES
a. Xy+z - x * y + z
b. 4y/27-5c/x - 4 * y / 27 5 * c / x
c. b+ (b2-4ac) - -b + (b ^ 2 4 * a * c) ^ 0.5
d. S=ut+1/2at2 - s = u * t 1 / 2 * a * t ^ 2
2. Evaluate the following expression given that x=2, y=3, z=5, b=10, a=4,
c=4
a. Xy+z
b. 4y/3-5c/x
c. b+ b2-4ac)
24
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
SOLUTION: BY USING BASIC HEIRACHY OF OPERATOR PRECEDENCE
a. Xy+z - x * y + z = 2 * 3 + 5 = 6 + 5 = 11
b. 4y/3-5c/x -4 * y / 3 5 * c / x = 4 * 3 / 3 5 * 4 / 2 = 4 10 = -6
c. b+ (b2-4ac) - -b + (b ^ 2 4 * a * c) ^ 0.5 = -10 + (10 ^ 2 4 *
4 * 4) ^ 0.5 = -10 + (100 -64) ^ 0.5 = -4
RELATIONAL OPERATORS
The following relational operators are used in testing a relation between two
entities
LOGICAL OPERATOR
These are based on conditional statements which are either true or false. We
have the following logical operators:
-AND logical AND indicate that logical expression X AND Y, is true (T) if
and only if X is true and Y is true
-NOT (logical operator NOT) indicates the negation or the reverse of a truth
value, i.e. NOT Y is true if Y is false, and false is Y is true.
25
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
These are system pre-coded routine, which are normally built as part of the
language interpreter/compiler available in its library: common built in
functions that are for solving mathematical problems are as follows:
LEFT (TEXT, SIZE): use to get the out string of the leftmost
number of the character of a string argument: for example:
26
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
The output is noon
BASIC STATEMENTS
Examples:
27
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
I. 10 REM program to compute area of circle.
II. REM Welcome to BASIC environment
NB: REM statement can come anywhere in the program; beside an
apostrophe can be used in place of REM statement as in: 20 Program to
display circle area.
Examples:
Nn Identifier= expression/values/variable
Examples:
28
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Syntax: nn PRINT string/values/variables/expression
Examples:
END Statements: this statement mark the terminating point for the
program. No executable statements should follow this statement since
execution of the main program ends at this statement.
Syntax: nn END
Examples:
I. 100 END
II. END
Syntax: nn STOP
Examples:
I. 20 STOP
II. STOP
Examples:
29
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Examples:
BOURNVITA #600.00
GOLDEN MORN #450.00
READ and DATA Statement: These two statements are used in pair
to allow input data items to be used in program. Unlike INPUT
statement, READ and DATA statement not only allow specification of
variable-list or data-item with READ but also gives room for the
provision of the corresponding data values for each of the specified
variables indicated by READ using the DATA statement written to
form part of the source code.
Example:
I. 10 READ A,B,C,D
30
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
SOLUTION
30 END
SOLUTION
30 END
d. Perimeter= 2(L+b)
SOLUTION:
30 INPUT R
40 LET V = 4 / 3 * PIE * R ^ 3
50 PRINT V
60 END
LET A = 1 / 2 * (a + b) * h
31
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT Area of trapezium=; A
END
END
32
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
condition or expression specified by the designated conditional
branching statement
Statements
END IF
PRINT A is greater
END IF
NB: from the example above, the statement PRINT A is greater will
be executed only if value of A is greater than B and nothing
happens otherwise.
Statement A
ELSE
Statements B
END IF
33
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Example: IF (A > B) THEN
PRINT A is greater
ELSE
PRINT B is greater
END IF
Statement 1
Statement 2
Statements N
ELSE
Statement N+1
END IF
Example: assuming we are given a table of score grade for CSC 102
as represented below:
70-100 A 5
60-69 B 4
34
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
50-59 C 3
45-49 D 2
40-44 E 1
BELOW 40 F 0
REM PROGRAM to test for score and generate grade, point for a
student
ELSE
LET GRADE$= F
LET POINT= 0
END IF
END
35
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
NB: this program above will allow any value between 0 and 100 to be read
and placed in variable score, test the value of score against the values
specified in each condition if the IFTHENELSEIF statement, then once
any of the condition evaluated to be true then the statement within that
block IF will be executed immediately; i.e. assuming we are given that score
= 53, this will allow the program to generate as output:
Grade is: C
Point is: 3
Since the condition: score>=50 AND score<=59 will be the only one
to evaluate to be true as the given score (53) lies between 50 and 59.
Example:
END
NB: The above program will allow value to read into I, the value of I will be
use to divide by 2, then the integer remainder resulting from this
division process will be tested against zero, once there is a match
then the input will be: I is an EVEN number.
I MOD 2= I - (I \ 2) * 2
IF I = 15, then
15 MOD 2= 15 - (15 \ 2) * 2 = 5 7 * 2 = 15 14 = 1
36
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Therefore 15 MOD 2 = 1
Example: 30 GOTO 70
70 END
NB: you should try to avoid unnecessary use of this statement has this
can cause indefinite/infinite execution of the program without end
(i.e. endless program execution): which in turn result into
damage/harm the processor and the memory of the system.
CASE VALUE 1
Statements1
CASE Value 2
Statement 2
CASE Value n
Statement n
CASE ELSE
Statement n+1
END SELECT
37
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Example: write a BASIC program using SELECT CASE Statement to
examine the value of a numeric variable called TEMP and display one of
the following message; depending on the value assign to TEMP:
INPUT TEMP
CASE 1
PRINT HOT
CASE 2
PRINT WARM
CASE 3
PRINT COLD
CASE 4
END SELECT
END
38
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Counter control looping: this is involved of a portion of program
repeatedly, for a specified/definite numbers of times.
Sentinel- Control looping: this involves execution of portion of
program one or more time until/while a particular condition is
satisfied.
Statement
NB: for the execution to occur within the body of the FOR-NEXT loop, the
initial value must be less than or equal to final value (i.e. initial value
<= final value), with a STEP of increment value (i.e. positive whole
number), Also, when the initial value greater than the final value (i.e.
initial value > final value), there must be decrement (i.e. negative
whole number) specified for the STEP.
Examples:
39
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
FOR I = 1 TO 100
PRINT I
NEXT I
END
ii. write a BASIC program to generate odd numbers and compute their
sum between 1 and 1000
LET SUM = 0
PRINT I
NEXT I
PRINT SUM
END
Syntax: WHILE
Statements
WEND
Example:
LET SUM = 0
LET I = 2
40
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT I
LET I = I + 2
WEND
PRINT SUM
END
Statements
LOOP
Examples:
LET PRODUCT = 1
LET I= 1
PRINT I
LET I = I + 2
LOOP
PRINT PRODUCT
END
41
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
II. REM program to compute product of even number and
generate even numbers.
LET PRODUCT = 1
LET I = 2
DO UNTIL (I > 100)
PRINT I
LET PRODUCT = PRODUCT * I
LET I = I + 2
LOOP
PRINT PRODUCT OF EVEN=; PRODUCT
END
Syntax: DO
Statements
Examples:
LET PRODUCT = 1
LET I = 1
DO
PRINT I
LET I = I + 2
END
42
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
II. REM program to compute products of even &
generate even number
LET PRODUCT = 1
LET I = 2
DO
PRINT I
LET I = I + 2
END
ARRAY
2 4 5 7 6 21
43
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
15
-1
50
74
e.g.
2 4 54 32 667 331
13 -33 44 21 44 53
2 4 7 3 20
TABLE A
To refer to the 2nd and 4th elements in the table above we say:
44
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
i.e. Array name (index/subscript) A (2), A(4)
Example:
1. Write a BASIC program that compute the sum and average (mean)
of N numbers
(HINT: 1 N 500 )
DIM X(500)
LET SUM = 0
FOR I = I TO N
INPUT X (I)
NEXT I
45
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT SUM=; SUM
ELSE
END IF
END
FOR I = 1 TO 3
FOR J = 1 TO 3
NEXT J
NEXT I
FOR I = 1 TO 3
FOR J= 1 TO 3
NEXT J
NEXT I
FOR I = 1 TO 3
FOR J = 1 TO 3
PRINT C(I,J)
46
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
NEXT J
NEXT I
END
47
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
MS-DOS stands for Microsoft Disk Operating System, it is a single
user operating system that allows only one user to perform task at a time. It
is command-oriented operating system that allows operation to be
performed with the use of commands (instructions).
o MS-DOS COMMANDS
PARTS OF COMMAND
I. THE COMMAND NAME: this specifies the action you want MS-DOS
to carry out. For example: DEL, COPY, CLS
II. PARAMETERS: this defines the object you want MS-DOS to act on.
For example, the Del(Erase) command requires a parameter that is
name of the file you want to delete. i.e. Del CSC102.txt
III. SWITCH: is a forward slash (/) usually followed by a letter o
number
If you want to stop MS-DOS from completing a command; press ctrl + break
+ C. Your command is cancelled and the command prompt appears.
The current drive appears as the first letter of the command prompt. On
most system if the letter is A or B, one of the floppy disk drive (51/4 or 31/2)
is the current drive.
To change the current drive, type the letter of the drive followed by a
colon. For example,
TYPES OF COMMAND
48
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
1. INTERNAL COMMAND: these are commands loaded into memory,
when you start your system and are placed in a file called
COMMAND.COM. Examples are: Dir, Del, Date, Time and so on.
2. EXTERNAL COMMANDS: these are command that are placed in
files on a disk and transferred from disk into memory for use.
Examples are: Chkdsk, format, COPY, XCOPY, etc.
CLS (clear screen): this is use to clear the screen of the MS-DOS, so that it
will only display command prompt and cursor. E.g. type the cls at the
command prompt i.e.
Syntax:
Examples:
49
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
COPY: use to copy one or more files from one location (drive or
directory) to another
SOURCE: specifies the location and the name of files from which you
want to copy. It may contain drive letter, colon followed by directory
name or filename
Examples:
This will allow all the files placed directly on drive C to move to a
directory name All_files on drive C
II. C:\> COPY C:\*.* A:\All_enteries (type and press the enter key)
This will move all the file placed/stored directly on drive C to a directory
called All entries on drive A.
III. C:\> COPY C:\BASIC\sample1.BAS C:\CSC 102 (type and press the
enter key)
This copy a title called sample1.BASfrom the directory named
BASIC on drive C to a directory called CSC 102 in drive C
IV. C:\> COPY C:\BASIC\*.BAS C:\CSC102 (type and press the enter
key)
This will move all the file with an extension .BAS from a directory
called BASIC on drive C to a directory known as CSC 102 on drive
C.
50
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
DIR: use to display a list of all files, directories or subdirectories that
are in the drive or directory specified.
Syntax: DIR or
Examples:
This display all file, directories and subdirectories in the drive C. The
list items may include the disks volume label, serial number,
directory or file name per line, the file size in bytes, the date and time
the file last modified, total number of files; their commutative size, the
free space (in byte) remaining on the disk.
II. C:\> DIR C:\BASIC\*.BAS /W/P (type and press enter key)
This display in wide format a list of only file name of files with
extension .BAS in directory BASIC, and pause each time the screen
fills until you press enter key to continue.
/P: causes the directory (Dir) to display only to pause once the
screen is filled.
Examples:
51
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
DISKCOPY drive1: drive2:
This copy the content of disk drive A and placed it disk drive C
Examples:
i. C:\> DEL CSC 102.txt- this delete the files called CSC102.txt
from disk on drive C
ii. C:\> DEL C:\test\CSC102.tmp- this deletes files: CSC102.tmp
from directory test on drive C
CHKDSK: check the status of a disk and display a status report such
as number of spaces used and free for use, check for error in disk.
FORMAT: specify to prepare or repair the disk for use. The FORMAT
command creates a new root directory and file allocation table for the
disk. It can also check for bad areas on the disk, and also delete all
the data on the disk.
52
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
MD(Make Directory): use to create new directory.
This will delete (remove) a directory named CSC102 from disk drive C.
TIME: displays the system time or set your computer internal clock.
Example:
DATE: to display the system date and set your computer date.
Syntax: DATE (date format)
Example:
i. C:\> DATE (type and press enter key)
53
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Visual basic provides the tools you need to create windows with familiar
elements like menus, text boxes, command button, option buttons, check
boxes, etc. Microsoft Windows uses a Graphical Users Interface (GUI).
54
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
which uses a different approach: Object Oriented Programming (OOP) and
event-driven programming. Microsoft refers to VB as an event-driven
programming language, which has many (but not all) elements of an object-
oriented programming language such as java.
TERMINOLOGIES IN VB
1. DESIGN TIME: this is the time at which VB application is being
developed.
2. BREAK TIME: this is the time when there is a pause in the execution
of the VB program.
3. RUN TIME: this is the time at which VB application developed is being
executed and tested.
4. FORM: this is a small windows or dialog representing a user interface
on which control are added in order to develop a VB application.
5. CONTROL: these are element or graphical representation of an object
added to a form in order to create VB application. Examples are:
labels, textboxes, checkboxes, option buttons, combo boxes, command
buttons etc.
6. OBJECT: this is the name used to refer combination of form and
control that make up the VB application.
7. PROPERTIES: these refer to attribute or behaviour or appearance of
an object. Examples are: Name, text, caption, back color, font, visible
etc. We can refer to a property of an object in a VB procedure as:
objectname.property= value e.g. text1.text = welcome!
8. METHOD: this refers to the action performed on object or action
performed by an object. Examples are: print, resize, show, hide, load,
unload etc. we can refer to a method of an object in a VB code as:
Object name. E.g. picture1.print welcome to FUTA
9. EVENT: These refer to what happen to an object when a user interacts
with the designed VB application. Examples are: click, load, activate,
unload, key press, mouse down, lost focus etc.
55
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
Objectname_event
VERSIONS OF VB
Microsoft Visual BASIC for windows comes in a working model, a
learning edition, a professional edition. Anyone planning to do
professional application development that includes the advanced
features of database management should use the professional edition,
enterprise edition, or express edition with .NET framework facilities.
INTRODUCING VB CONTROLS:
I. TEXT BOXES: we do use a text box control when we want the user to
type some input, to allow user to modify the content of any
information or message, to create a text editor window, and to display
an editable report. Some commonly used properties of text box are:
56
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
text, name, alignment, font, multi line, maxlength etc. the 3 letter
prefix for naming a textbox is txt. E.g. txtlenght
II. LABEL: we use a label control when we want the user to view some
output, to label; or name other control on form, to display any
information whose content cannot be modified, to generate non-
editable report. Some common properties of label are: caption, name,
font, backcolor, alignment etc.
The 3- letter prefix for naming a label is lbl e.g lblarea
III. FRAMES: frames are used as containers for other controls. Usually,
group o option buttons or check boxes are placed in frames. Using
frames to group controls make your forms easier to understand. Some
common properties include; caption, name etc. the 3- letter prefix for
naming a frame is fra. E.g. fracolor.
IV. CHECKBOXES: check boxes allow the user to select (or deselect) an
option. In any group of checkboxes, any number of them may be
selected. The value properties of a checkbox are set to 0 if unchecked,
1 if checked, 2 if greyed (disabled).
57
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
1. CLS
REM PROGRAM TO COMPUTE THE FACTORIAL OF N POSITIVE INTEGERS
LET FACT = 1
INPUT ENTER ANY POSITIVE INTEGER N: ; N
IF(N < 0) THEN
PRINT INVALID INPUT! ENSURE YOU ENTER A POSITIVE NUMBER
ELSE
FOR I = N TO 1 STEP -1
LET FACT = FACT * I
NEXT I
PRINT FACTORIAL OF ; N; =;FACT
ENDIF
END
2. CLS
REM PROGRAM TO COMPUTE THE ROOTS OF A QUADRATIC EQUATION USING QUADRATIC
FORMULAE
INPUT ENTER VALUE FOR A; A
INPUT ENTER VALUE FOR B; B
INPUT ENTER VALUE FOR C; C
LET D = B ^ 2 (4 * A * C)
IF (D < 0) THEN
PRINT COMPLEX ROOTS
ELSEIF(D = 0)THEN
LET X1 = -B /(2 * A)
PRINT EQUAL ROOTS:;X1
ELSE
LET X1 = (-B + SQR(B ^ 2 4 * A * C))/(2 * A)
LET X1 = (-B - SQR(B ^ 2 4 * A * C))/(2 * A)
PRINT ROOT1 =; X1; ROOT2 =; X2
ENDIF
END
3. CLS
REM PROGRAM TO COMPUTE THE SUM OF THE SQUARE OF N NUMBERS
LET SUMSQ = 0
INPUT ENTER ANY POSITIVE INTEGER N:; N
FOR I = 1 TO N
LET SUMSQ = SUMSQ + (I ^ 2)
NEXT I
PRINT THE SUM OF THE SQUARE OF N NUMBERS:; SUMSQ
END
4. CLS
REM PROGRAM TO GENERATE EVEN NUMBERS BETWEEN 1 AND 100 AND THEIR SUM
LET SUMEVEN = 0
PRINT EVEN NUMBERS
FOR I = 2 TO 100 STEP 2
PRINT I
LET SUMEVEN = SUMEVEN + I
NEXT I
PRINT SUM OF EVEN NUMBERS BETWEEN 1 AND 100 IS; SUMEVEN
END
5. CLS
REM PROGRAM TO GENERATE EVEN NUMBERS BETWEEN 1 AND 100 AND THEIR PRODUCTS
58
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
LET PRDTEVEN = 1
PRINT EVEN NUMBERS
FOR I = 2 TO 100 STEP 2
PRINT I
LET PRDTEVEN = PRDTEVEN * I
NEXT I
PRINT PRODUCT OF EVEN NUMBERS BETWEEN 1 AND 100 IS; PRDTEVEN
END
6. CLS
REM PROGRAM TO GENERATE ODD NUMBERS BETWEEN 1 AND 100 AND THEIR SUM
LET SUMODD = 0
PRINT ODD NUMBERS
FOR I = 1 TO 100 STEP 2
PRINT I
LET SUMODD = SUMODD + I
NEXT I
PRINT SUM OF ODD NUMBERS BETWEEN 1 AND 100 IS; SUMODD
END
7. CLS
REM PROGRAM TO GENERATE ODD NUMBERS BETWEEN 1 AND 100 AND THEIR PRODUCTS
LET PRDTODD = 1
PRINT ODD NUMBERS
FOR I = 1 TO 100 STEP 2
PRINT I
LET PRDTODD = PRDTODD * I
NEXT I
PRINT PRODUCT OF ODD NUMBERS BETWEEN 1 AND 100 IS; PRDTODD
END
8. CLS
REM PROGRAM TO GENERATE SUM OF ALL EVEN NUMBERS, SUM OF THE SQUARE OF EVEN
NUMBERS, REM AND PRODUCT OF THE SUM OF THE SQUARE AND SUM OF ALL EVEN
BETWEEN 1 AND 100
LET SUM = 0
LET SUMSQ = 0
PRINT EVEN NUMBERS; SQUARE OF EVEN NUMBERS
FOR I = 2 TO 100 STEP 2
PRINT I, I ^ 2
LET SUM = SUM + I
LET SUMSQ = SUMSQ + (I ^ 2)
NEXT I
LET PRODUCT = SUM * SUMSQ
PRINT THE SUM OF ALL EVEN NUMBERS BETWEEN 1 AND 100 =; SUM
PRINT THE SUM OF THE SQUARE OF EVEN NUMBERS BETWEEN 1 AND 100 =; SUMSQ
PRINT THE PRODUCT OF SUMS OF ALL EVEN NUMBERS BETWEEN 1 AND 100 =; PRODUCT
END
9. CLS
REM PROGRAM TO CONVERT DOLLARS TO NAIRA IF 1 DOLLAR = 200 NAIRA
INPUT ENTER THE AMOUNT IN DOLLARS:; AMT
LET NAMT = AMT * 200
PRINT AMT; IN DOLLAR IS; NAMT; NAIRA
END
10.
CLS
REM PROGRAM TO ACCEPT A STUDENT SURNAME, MIDDLE NAME, AND FIRST NAME, THEN
REM CONCANTENATE(JOIN) THEM INTO A VARIABLE CALLED NAME
INPUT READ IN YOUR SURNAME; SURNAME$
INPUT READ IN YOUR MIDDLE NAME; MIDDLENAME$
INPUT READ IN YOUR FIRST NAME; FIRSTNAME$
LET NAME$ = SURNAME$ + + MIDDLENAME$ + + FIRSTNAME$
59
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT YOUR FULL NAME IS ; NAME$
END
11.
CLS
REM PROGRAM TO GENERATE ALL THE FACTORS OF A GIVEN INTEGER NUMBER
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT FACTORS OF; N; ARE:
FOR I = 1 TO N
IF(N MOD I = 0) THEN
PRINT I
ENDIF
NEXT I
END
12.
CLS
REM PROGRAM TO GENERATE ALL THE FACTORS OF A GIVEN INTEGER NUMBER AND THEIR SUM
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT FACTORS OF; N; ARE:
FOR I = 1 TO N
IF(N MOD I = 0) THEN
PRINT I
LET SUM = SUM + I
ENDIF
NEXT I
PRINT THE SUM OF THE FACTORS OF; N; =; SUM
END
13.
CLS
REM PROGRAM TO GENERATE ALL THE FACTORS OF A GIVEN INTEGER NUMBER AND THEIR PRODUCT
LET PRODUCT = 1
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT FACTORS OF; N; ARE:
FOR I = 1 TO N
IF(N MOD I = 0) THEN
PRINT I
LET PRODUCT = PRODUCT * I
ENDIF
NEXT I
PRINT THE PRODUCT OF THE FACTORS OF; N; =; PRODUCT
END
14.
CLS
REM PROGRAM TO GENERATE ALL THE MULTIPLES OF A GIVEN INTEGER NUMBER BTW 1 AND 100
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT MULTIPLES OF; N; ARE:
60
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
FOR I = 1 TO 100
IF(I MOD N = 0) THEN
PRINT I
ENDIF
NEXT I
END
15.
CLS
REM PROGRAM TO COMPUTE THE SUM OF MULTIPLE OF A GIVEN INTEGER NUMBER BTW 1 AND 100
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT MULTIPLES OF; N; ARE:
FOR I = 1 TO 100
IF(I MOD N = 0) THEN
PRINT I
LET SUM = SUM + I
ENDIF
NEXT I
PRINT THE SUM OF THE MULTIPLES OF; N; =; SUM
END
16.
CLS
REM PROGRAM TO COMPUTE THE PRODUCT OF MULTIPLE OF A GIVEN INTEGER NUMBER BTW 1 -
100
LET PRODUCT = 1
INPUT ENTER ANY POSITIVE INTEGER NUMBER N:; N
PRINT MULTIPLES OF; N; ARE:
FOR I = 1 TO 100
IF (I MOD N = 0) THEN
PRINT I
LET PRODUCT = PRODUCT * I
ENDIF
NEXT I
PRINT THE PRODUCT OF THE MULTIPLES OF; N; =; PRODUCT
END
17.
REM PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND 100
PRINT PRIME NUMBERS ARE:
FOR I = 2 TO 100
FOR J = 2 TO I-1
IF (I MOD J = 0) THEN 60
NEXT J
PRINT I
60 NEXT I
END
61
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
18.
CLS
REM PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND 100 AND THEIR SUM
LET SUM = 0
PRINT PRIME NUMBERS ARE:
FOR I = 2 TO 100
FOR J = 2 TO I-1
IF (I MOD J = 0) THEN 60
NEXT J
PRINT I
LET SUM = SUM + I
60 NEXT I
PRINT THE SUM OF ALL PRIME NUMBERS BTW 1 AND 100 =; SUM
END
19.
CLS
REM PROGRAM TO GENERATE PRIME NUMBERS BETWEEN 1 AND 100 AND THEIR PRODUCT
LET PRODUCT = 1
PRINT PRIME NUMBERS ARE:
FOR I = 2 TO 100
FOR J = 2 TO I-1
IF (I MOD J = 0) THEN 60
NEXT J
PRINT I
LET PRODUCT = PRODUCT * I
60 NEXT I
PRINT THE PRODUCT OF ALL PRIME NUMBERS BTW 1 AND 100 =; PRODUCT
END
20. SOLUTION TO ACTIVITY 4-1(PG. 38) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO DETERMINE WHETHER AN INTEGER NUMBER IS A PRIME OR COMPOSITE NUMBER
INPUT READ IN ANY INTEGER NUMBER N:; N
IF (N <= 1) THEN
PRINT NUMBER MUST BE POSITIVE!
ELSE
FOR J = 2 TO N-1
IF (N MOD J = 0) THEN 70
NEXT J
PRINT N; IS A PRIME NUMBER
GOTO 80
ENDIF
70 PRINT N; IS A COMPOSITE NUMBER
80 END
21.
CLS
62
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
REM PROGRAM TO DETERMINE WHETHER A NUMBER IS ODD NUMBER, EVEN NUMBER, OR PRIME
NUMBER
INPUT READ IN ANY INTEGER NUMBER N:; N
IF (N MOD 2 = 0) THEN
PRINT N; IS AN EVEN NUMBER
ELSE
PRINT N; IS AN ODD NUMBER
ENDIF
IF (N <= 1) THEN
PRINT NUMBER MUST BE POSITIVE!
ELSE
FOR J = 2 TO N-1
IF (N MOD J = 0) THEN 70
NEXT J
PRINT N; IS A PRIME NUMBER
GOTO 80
ENDIF
70 PRINT N; IS A COMPOSITE (NOT PRIME) NUMBER
80 END
22.
CLS
REM PROGRAM TO DETERMINE WHETHER A POSITIVE INTEGER NUMBER IS A PERFECT NUMBER
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER N:; N
FOR I = 1, N-1
IF (N MOD I = 0) THEN
LET SUM = SUM + I
PRINT FACTOR =; I
ENDIF
NEXT I
IF(SUM = N) THEN
PRINT N; IS A PERFECT NUMBER
ENDIF
END
23.
REM PROGRAM TO DETERMINE WHETHER A POSITIVE INTEGER NUMBER IS A DEFICIENCY NUMBER
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER N:; N
FOR I = 1, N-1
IF (N MOD I = 0) THEN
LET SUM = SUM + I
PRINT FACTOR =; I
ENDIF
NEXT I
IF (SUM < N) THEN
PRINT N; IS A DEFICIENCY NUMBER
63
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
ENDIF
END
24.
CLS
REM PROGRAM TO DETERMINE WHETHER A POSITIVE INTEGER NUMBER IS AN EXCESS/SURPLUS
NUMBER
LET SUM = 0
INPUT ENTER ANY POSITIVE INTEGER N:; N
FOR I = 1, N-1
IF (N MOD I = 0) THEN
LET SUM = SUM + I
PRINT FACTOR =; I
ENDIF
NEXT I
IF (SUM > N) THEN
PRINT N; IS AN EXCESS NUMBER
ENDIF
END
25.
CLS
REM PROGRAM TO COMPUTE THE INVERSE/RECIPROCAL OF EVEN NOS BTW 130 AND THEIR
PRODUCT
LET PRODUCT = 1
FOR I = 2 TO 30 STEP 2
PRINT INVERSE OF; I; =; 1 / I
LET PRODUCT = PRODUCT * (1 / I)
NEXT I
PRINT PROUCT OF INVERSE =; PRODUCT
END
26.
CLS
REM PROGRAM TO DETERMINE EVEN NUMBERS BTW 1-50 THOSE THAT ARE MULTIPLE OF 3
FOR I = 2 TO 50 STEP 2
IF (I MOD 3 = 0) THEN
PRINT I
ENDIF
NEXT I
END
27.
CLS
REM PROGRAM TO GENERATE A FIBONACCI NUMBERS
LET F1 = 1
LET F2 = 1
INPUT ENTER ANY POSITIVE INTEGER GREATER THAN 2; N
IF (N < 3) THEN
PRINT F1, F2
64
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
ELSE
PRINT F1; F2;
FOR I = 3 TO N
LET FIB = F1 + F2
LET F1 = F2
LET F2 = FIB
PRINT FIB;
NEXT I
ENDIF
END
28.
CLS
REM PROGRAM TO READ IN A CHARACTER AND DETERMINE WHETHER CHARACTER IS ALPHABET,
REM DIGIT OR SYMBOLIC CHARACTER
INPUT PRESS IN ANY CHARACTER FROM THE KEYBOARD; C$
IF ((C$ >= A AND C$ <= Z) OR (C$ >= a AND C$ <= z)) THEN
PRINT C$; IS AN ALPHABET/LETTER
ELSEIF ((C$ >= 0 AND C$ <= 9)) THEN
PRINT C$; IS A DIGIT/NUMBER
ELSE
PRINT C$; IS A SYMBOLIC CHARACTER
ENDIF
END
29.
CLS
REM PROGRAM TO COMPUTE THE SUM AND AVERAGE(MEAN) OF N NUMBERS
DIM X(1000)
LET SUM = 0
INPUT READ IN ANY POSITIVE INTEGER NUMBER; N
FOR I = 1 TO N
INPUT X(I)
LET SUM = SUM + X(I)
NEXT I
LET MEAN = SUM / N
PRINT SUM OF THE GIVEN NUMBERS =; SUM
PRINT MEAN (AVERAGE) OF THE GIVEN NUMBERS =; MEAN
END
30.
CLS
REM PROGRAM THAT COMPUTE THE PERMUTATION OF NUMBERS
LET F1 = 1
LET F2 = 1
INPUT ENTER ANY POSITIVE INTEGER N:; N
INPUT ENTER ANY POSITIVE INTEGER R:; R
IF (R > N) THEN
PRINT R; MUST NOT BE GREATER THAN; R
65
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
ELSE
TO COMPUTE N FACTORIAL
FOR I = N TO 1 STEP -1
LET F1 = F1 * I
NEXT I
TO COMPUTE N-R FACTORIAL
FOR J = (N R) TO 1 STEP -1
LET F2 = F2 * J
NEXT J
LET PERM = F1 / F2
PRINT PERMUTATION OF NUMBER =; PERM
ENDIF
END
31.
CLS
REM PROGRAM THAT COMPUTE THE COMBINATION OF NUMBERS
LET F1 = 1
LET F2 = 1
LET F3 = 1
INPUT ENTER ANY POSITIVE INTEGER N:; N
INPUT ENTER ANY POSITIVE INTEGER R:; R
IF (R > N) THEN
PRINT R; MUST NOT BE GREATER THAN; R
ELSE
TO COMPUTE N FACTORIAL
FOR I = N TO 1 STEP -1
LET F1 = F1 * I
NEXT I
TO COMPUTE N-R FACTORIAL
FOR J = (N R) TO 1 STEP -1
LET F2 = F2 * J
NEXT J
TO COMPUTE R FACTORIAL
FOR K = R TO 1 STEP -1
LET F3 = F3 * K
NEXT K
LET COMB = F1 / (F2 * F3)
PRINT COMBINATION OF NUMBER =; COMB
ENDIF
END
32.
CLS
REM PROGRAM THAT GENERATE THE LARGEST (MAXIMUM) OF 10 DIFFERENT NUMBERS
DIM X(10)
PRINT READ IN 10 DIFFERENT NUMBERS
FOR I = 1 TO 10
66
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
INPUT X(I)
NEXT I
LARGEST = X(1)
FOR I = 2 TO 10
IF (LARGEST < X(I))THEN
LARGEST = X(I)
ENDIF
NEXT I
PRINT THE LARGEST (MAXIMUM) OF 10 NUMBERS =; LARGEST
END
33.
CLS
REM PROGRAM THAT GENERATE THE LEAST (MINIMUM) OF 10 DIFFERENT NUMBERS
DIM X(10)
PRINT READ IN 10 DIFFERENT NUMBERS
FOR I = 1 TO 10
INPUT X(I)
NEXT I
LEAST = X(1)
FOR I = 2 TO 10
IF (LEAST > X(I))THEN
LEAST = X(I)
ENDIF
NEXT I
PRINT THE LEAST (MINIMUM) OF 10 NUMBERS =; LEAST
END
34.
REM TO COMPUTE THE SUM OF 2 X 2 MATRICES
DIM A(2,2), B(2,2), C(2,2)
PRINT READ IN ELEMENTS IN MATRIX A:
FOR I = 1 TO 2
FOR J = 1 TO 2
INPUT A(I,J)
NEXT J
NEXT I
PRINT READ IN ELEMENTS IN MATRIX B:
FOR I = 1 TO 2
FOR J = 1 TO 2
INPUT B(I,J)
NEXT J
NEXT I
PRINT THE SUM OF ELEMENTS IN MATRIX A AND B ARE:
FOR I = 1 TO 2
FOR J = 1 TO 2
LET C(I,J) = A(I,J) + B(I,J)
PRINT C(I,J),
67
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
NEXT J
PRINT
NEXT I
END
35.
CLS
REM TO COMPUTE THE PRODUCT OF 2 X 2 MATRICES A AND B
DIM A(2,2), B(2,2), C(2,2)
PRINT READ IN ELEMENTS IN MATRIX A:
FOR I = 1 TO 2
FOR J = 1 TO 2
INPUT A(I,J)
NEXT J
NEXT I
PRINT READ IN ELEMENTS IN MATRIX B:
FOR I = 1 TO 2
FOR J = 1 TO 2
INPUT B(I,J)
NEXT J
NEXT I
PRINT THE PRODUCT OF ELEMENTS IN MATRIX A AND B ARE:
FOR I = 1 TO 2
FOR J = 1 TO 2
LET C(I,J) = 0
FOR K = 1 TO 2
LET C(I,J) = C(I,J) +(A(I,K) * B(K,J))
NEXT K
PRINT C(I,J),
NEXT J
PRINT
NEXT I
END
36.
CLS
REM PROGRAM TO COMPUTE THE ARITHMETIC MEAN, HARMONIC MEAN, GEOMETRIC MEAN OF 3 NOS
INPUT ENTER VALUE FOR X:; X
INPUT ENTER VALUE FOR Y:; Y
INPUT ENTER VALUE FOR Z:; Z
LET ARITH_MEAN = 1 / 3 * (X + Y + Z)
LET GEOM_MEAN = (X * Y * Z) ^ (1 / 3)
LET HARM_MEAN = 3 / ((1 / X) + (1 / Y) + (1 / Z))
PRINT THE ARITHMETIC MEAN =; ARITH_MEAN
PRINT THE GEOMETRIC MEAN =; GEOM_MEAN
PRINT THE HARMONIC MEAN =; HARM_MEAN
END
37.
68
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
CLS
REM PROGRAM TO COMPUTE THE AREA OF TRIANGLE USING HEROES FORMULAE
INPUT ENTER VALUE FOR A:; A
INPUT ENTER VALUE FOR B:; B
INPUT ENTER VALUE FOR C:; C
LET S = (A + B + C) / 2
LET AR = S * (S A) * (S B) * (S C)
IF (AR <= 0) THEN
PRINT AREA HAS COMPLEX ROOT OR ZERO ROOT = 0
ELSE
LET AREA = SQR(AR)
PRINT AREA OF TRIANGLE =; AR
ENDIF
END
38.
CLS
REM PROGRAM TO CONVERT METERS TO INCHES, AND YARD
INPUT ENTER THE VALUE IN METERS; M
LET INCH = 39.37 * M
LET YARD = INCH / 36
PRINT INCHES =; INCH; YARD =; YARD
END
39.
CLS
REM PROGRAM TO CONVERT TIME IN SECONDS TO HOURS AND MINUTES EQUIVALENT
INPUT READ IN TIME IN SECONDS; SECS
LET HRS = SECS \ 3600
LET SECS = SECS MOD (HRS * 3600)
LET MINS = SECS \ 60
PRINT THE EQUIVALENT TIME IS; HRS; HOURS :; MINS; MINUTES
END
40.
CLS
REM PROGRAM THAT GENERATE ALL INTEGERS BTW 1-50 AND SKIP THOSE THAT MULTIPLE OF 5
FOR I = 1 TO 50
IF (I MOD 5 = 0) THEN 30
PRINT I
30 NEXT I
END
41. SOLUTION TO ACTIVITY 4-3(PG. 39) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO FIND THE SUM OF AND AVERAGE OF ALL THE MULTIPLE OF 5 BETWEEN 1 AND
100
LET COUNT = 0
LET SUM = 0
FOR I = 1 TO 100
69
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
IF (I MOD 5 = 0) THEN
PRINT I;
LET SUM = SUM + I
LET COUNT = COUNT + 1
ENDIF
NEXT I
LET AVERAGE = SUM / COUNT
PRINT THE SUM OF ALL THE MULTIPLE OF 5 BTW 1 AND 100 =; SUM
PRINT THE AVERAGE OF ALL THE MULTIPLE OF 5 BTW 1 AND 100 =; AVERAGE
END
42. SOLUTION TO ACTIVITY 5-2(PG. 41) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO PRODUCE THE EIGHT TRIPLES OF 0 AND 1 SUCH AS 000, 001, 010,
FOR I = 0 TO 1
FOR J = 0 TO 1
FOR K = 0 TO 1
PRINT I; J; K
NEXT K
NEXT J
NEXT I
END
43. SOLUTION TO ACTIVITY 5-3(PG. 41) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO COMPUTE THE INNER PRODUCT OF VECTOR HAVING 10 COMPONENTS SUCH AS
(3,5,4,6,4,3,5,4,3,5) AND (4,4,5,6,7,4,5,4,3,5)
DIM VECTOR1(10), VECTOR2(10)
LET SUM = 0
PRINT READ IN ELEMENTS OF VECTOR 1:
FOR I = 1 TO 10
INPUT VECTOR1(I)
NEXT I
PRINT READ IN ELEMENTS OF VECTOR 2:
FOR I = 1 TO 10
INPUT VECTOR2(I)
NEXT I
FOR I = 1 TO 10
LET SUM = SUM + (VECTOR1(I) * VECTOR2(I))
NEXT I
PRINT THE INNER PRODUCT OF 2 VECTORS IS:; SUM
END
44. SOLUTION TO ACTIVITY 5-5(PG. 41) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO SORT A GIVEN SET NUMBERS IN ASCENDING AND DESCENDING ORDER
DIM SET(100)
30 INPUT READ IN THE NUMBER OF ELEMENTS IN THE SET:; N
IF(N <= 1 OR N > 100) THEN
70
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT NUMER MUST BE BETWEEN 2 AND 100: TRY AGAIN WITH CORRECT VALUE
GOTO 30
ELSE
PRINT READ IN ALL ELEMENTS IN THE SET:
FOR I = 1 TO N
INPUT SET(I)
NEXT I
FOR I = 1 TO N - 1
FOR J = I + 1 TO N
IF(SET(J-1) > SET(J)) THEN
TEMP = SET(J-1)
SET(J-1) = SET(J)
SET(J) = TEMP
ENDIF
NEXT J
NEXT I
PRINT SET OF NUMBERS IN ASCENDING ORDER IS:
FOR I = 1 TO N
PRINT SET(I);
NEXT I
PRINT: PRINT SET OF NUMBERS IN DESCENDING ORDER IS:
FOR I = N TO 1 STEP -1
PRINT SET(I);
NEXT I
ENDIF
END
45. SOLUTION TO ACTIVITY 6-2(PG. 42) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO CHECK ENTERED LETTER IF IT IS CAPITAL(UPPERCASE) OR SMALL(LOWERCASE)
INPUT PRESS IN ANY ALPHABETICAL CHARACTER FROM THE KEYBOARD; C$
IF (C$ >= A AND C$ <= Z) THEN
PRINT C$; IS A CAPITAL(UPPERCASE) ALPHABET/LETTER
ELSE IF (C$ >= a AND C$ <= z) THEN
PRINT C$; IS A SMALL(LOWERCASE) ALPHABET/LETTER
ELSE
PRINT C$; IS NOT A LETTER/ALPHABET
ENDIF
END
46. SOLUTION TO ACTIVITY 6-3(PG. 42) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO REVERSE A GIVEN STRING
INPUT READ IN ANY STRING; TEXT$
FOR I = LEN(TEXT$) TO 1 STEP -1
REVTEXT$ = REVTEXT$ + MID$(TEXT$, I, 1)
NEXT I
71
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
PRINT THE REVERSE OF STRING:;TEXT$; IS:; REVTEXT$
END
47. SOLUTION TO ACTIVITY 6-4(PG. 42) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO GENERATE A TRIANGLE OF A STRING OF 5 NUMBERS (e.g. 12345)
INPUT READ IN ANY STRING OF NUMBERS; TEXT$
PRINT THE TRIANGULAR FORM OF STRING:
FOR I = LEN(TEXT$) TO 1 STEP -1
PRINT MID$(TEXT$, 1, I)
NEXT I
END
48. SOLUTION TO ACTIVITY 6-1(PG. 42) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO READ A PERSONS FIRST, MIDDLE AND LAST NAMES AND EXTRACT THEIR
INITIALS
INPUT ENTER A PERSONS FIRST NAME:; FIRST$
INPUT ENTER A PERSONS MIDDLE NAME:; MIDDLE$
INPUT ENTER A PERSONS LAST NAME:; LAST$
PRINT THE INITIALS OF A PERSONS NAME ARE:
PRINT LEFT$(FIRST$,1); LEFT$(MIDDLE$,1); LEFT$(LAST$,1)
END
49. SOLUTION TO ACTIVITY 8-9(PG. 46) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM TO CHECK WHETHER A GIVEN STRING OF NUMBER IS A PALINDROME OR NOT
INPUT READ IN ANY STRING OF NUMBER; NUMB$
FOR I = LEN(NUMB$) TO 1 STEP -1
REVNUMB$ = REVNUMB$ + MID$(NUMB$, I, 1)
NEXT I
IF (REVNUMB$ = NUMB$) THEN
PRINT THE STRING OF NUMBER:; NUMB$; IS A PALINDROME
ELSE
PRINT THE STRING OF NUMBER:; NUMB$; IS NOT A PALINDROME
ENDIF
END
50. SOLUTION TO ACTIVITY 5-1(PG. 40) IN THE PRACTICAL MANUAL
CLS
REM PROGRAM USING FOR NEXT LOOP TO CALCULATE THE SUM OF EVERY THIRD INTEGER
BEGINNING WITH I = 2 (I.E. CALCULATE THE SUM 2+5+7+8+11+13+14+ )FOR ALL VALUES OF
I < 100
LET SUM = 0
LET K = 3
LET I = 2
FOR J = 2 TO 99
IF (I >= 100) THEN GOTO 50
PRINT I;
LET SUM = SUM + I
72
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
LET I = I + K
LET K = K 1
IF (K < 1) THEN K = 3
NEXT J
50 PRINT SUM OF THE SERIES =; SUM
END
* KEYNOTES
73
COURTESY: EDUCATION COMMITTEE, MSSN FUTA, OBAKEKERE MOSQUE (08161885095,
08069018655)
DOWNLOADED FROM FUTABASE.COM
READ YOUR BOOK VERY WELL
BE FOCUS AND AIM HIGH
SUPPLICATE TO ALLAH(SWT)
BE CLOSE TO YOUR CREATOR AND MOVE AWAY FROM SINS
FEAR ALLAH MOST
74