0% found this document useful (0 votes)
3 views12 pages

Class 6 Basic Programming

The document provides an overview of BASIC programming, focusing on variables, commands, and sample programs. It explains numeric and string variables, how to use commands like LET, PRINT, and INPUT, and includes exercises to reinforce understanding. Additionally, it outlines rules for naming variables and presents various sample programs for practical application.

Uploaded by

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

Class 6 Basic Programming

The document provides an overview of BASIC programming, focusing on variables, commands, and sample programs. It explains numeric and string variables, how to use commands like LET, PRINT, and INPUT, and includes exercises to reinforce understanding. Additionally, it outlines rules for naming variables and presents various sample programs for practical application.

Uploaded by

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

Notes on BASIC PROGRAMMING

Variable

It is a location in the memory of the computer which stores values or data.

Depending on the type ofvalue or data stored, variables are of two types.

Numeric Variable and String Variable.

Numeric Variable

The variable that holds a numeric value for arithmetic calculations is called
numeric variable.

e.g. LET A=50

Here A is the numeric variable since it is used to store a number, 50.

String Variable

The variable that holds an alphanumeric value (combination of numbers and


letters of the alphabet) is called a string/alphanumeric variable.The string
variable must end with a $ sign. The value assigned to a string variable must be
enclosed within a pair of double inverted commas.

e.g.

LET N$= “Anirban”

LET ADDRESS$= “318 PRANTIK PALLY”

Check your progress 1:

Consider the following code:

LET X=23

LET Y=32

LET NAME$= “ENID BLYTON”


LET SUM=X+Y

Can you figure out the following?

a) How many numeric variables have been used in the above code?
b) What kind of variable is NAME$ ?
c) What will be the value stored in the variable SUM?

Commands used in BASIC:

LET

This command assigns a value to a variable in a program.

Eg.

LET P=20

LET C$= “ABC”

Here 20 is assigned to variable P and “ABC” is assigned to variable C$.

Hope you remember what kind of variables are P and C$ ?

PRINT

This command is used to display the output on the screen.

Eg. 1:

LET A=7

LET B=5

LET C=A-B

PRINT C

END

OUTPUT:

(After running the above program, the output will be displayed as 2).
Eg. 2:

LET NAME$= “ARUN”

LET AGE=12

PRINT “THE NAME IS-”; NAME$

PRINT “THE AGE IS-”; AGE

END

OUTPUT:

THE NAME IS-ARUN

THE AGE IS-12

INPUT

This command allows the user to enter a value for the variable while running
the program.

e.g.

INPUT “Enter a number” ; A

INPUT “Enter a name”; G$

After you execute the two lines given above, the program is going to ask you for
a number and a name. You can then type in any number and name of your
choice. The number you provide will be stored in the variable A. The name that
you provide will be stored in the variable G$.

END

This command is given at the end of the program. Statements written after END
are not executed. The END command is optional in a program.

Check your progress 2:

Consider the following code and answer the given questions:


INPUT “ENTER A NUMBER”; P

INPUT “ENTER ANOTHER NUMBER”; Q

LET R=(P+Q)/2

PRINT R

END

Questions:

a) When will we input the values of P and Q?


b) What will be the output if we input the values of P and Q as 10 and 20?

RULES FOR NAMING VARIABLES:

1. A variable name cannot start with a number.

2. A valid variable name ending with a $ sign represents a string variable.


But a variable name cannot have more than one $ sign.

3. No special characters except $ , # and ! signs are allowed in a variable


name. A variable name may contain only one special character and that
too at the end of the name.

4. A valid variable name that does not end with a $ sign represents a
numeric variable.
Eg.
a. DF is a NUMERIC variable.
b. DF$ is a STRING variable.
c. 98LK is INVALID because a variable name cannot start with a
number.
d. DF67 is NUMERIC because numbers are allowed at the end or in
between a variable name.
e. AM# is NUMERIC because # is allowed in a variable name and is at
the end.
f. U$$ is INVALID because two special characters are not allowed in a
variable name.
g. GARDEN! is NUMERIC because ! is allowed in a variable name and
is at the end.
Check your progress 3:
Identify the following variables as Numeric, String or Invalid.

a. AB
b. AB$
c. 7JH
d. GARGI90
e. DIJ#
f. K$$
g. AVIRAJ!
h. MUN@
i. K#P
j. KP#
k. DGY#$
l. ER45TP
m. Y_U
n. V98
o. G7H9
p. DEEP87$
q. ARUN IS GOOD

BASIC PROGRAMS

WAP in BASIC to find the value of a2 + b2 + c2 , where a=2, b=3 and c=5.

LET A=2

LET B=3

LET C=5

LET ANS = (A^2) + (B^2) + (C^2)

PRINT “ THE ANSWER IS ” ; ANS

END

In a class of 30 pupils, 25 are present on a particular day. Write a program


in BASIC to calculate the number of pupils absent and the percentage of
absentees.
LET TOT = 30

LET P = 25

LET A = TOT – P

LET PA = A / TOT * 100

PRINT “ THE TOTAL NUMBER OF PUPILS ABSENT”; A

PRINT “ THE PERCENTAGE OF ABSENTEES”; PA

END

The selling price of an item is ₹28600 and its cost price is ₹25000.
Write a program in BASIC to calculate and display the amount of profit
and the profit percentage.

LET SP=28600
LET CP=25000
LET P=SP-CP
LET PP=P/CP*100
PRINT "THE AMOUNT OF PROFIT IS";P
PRINT "THE PROFIT PERCENTAGE IS";PP
END

The length of a rectangle is 50 cm and the breadth is 25 cm. Write a


program to calculate and display the area and perimeter of the rectangle.

LET L=50
LET B=25
LET AR=L*B
LET PERI=2*(L+B)
PRINT “THE AREA IN SQ. CM. IS ”; AR
PRINT “THE PERIMETER IN CM. IS ”; PERI
END
The price of an item is ₹600. The shopkeeper gives a discount of 20%.
Write a program in BASIC to calculate and print the amount of discount
and selling price of the item.

LET P=600
LET DIS=20/100*P
LET SP=P-DIS
PRINT “THE AMOUNT OF DISCOUNT IS RS.”;DIS
PRINT “THE SELLING PRICE IS RS.”;SP
END

A store places an order for 100 pieces of an item. The cost of each item is
₹800. There is a discount of 10% on the item. Write a program in BASIC
to calculate and display the total amount that has to be paid by the store.

LET N=100
LET P=800
LET TOT=P*N
LET D=10/100*TOT
LET PAYMENT=TOT-D
PRINT “THE AMOUNT OF DISCOUNT IS ₹”;D
PRINT “THE AMOUNT TO BE PAID IS ₹”; PAYMENT
END

The following table shows the list of items imported by XY Ltd.


ITEMS PRICE(₹) QUANTITY
A 20 100
B 30 150
C 15 125
Write a program in BASIC to calculate the total cost of each item. The
company has to pay a fixed tax of 15% on the total cost. Calculate and
print the expenses of the company.
LET PA=20
LET QA=100
LET TA=PA*QA
LET PB=30
LET QB=150
LET TB=PB*QB
LET PC=15
LET QC=125
LET TC=PC*QC
LET TOT=TA+TB+TC
LET TAX=15/100*TOT
LET TOTPAID=TOT+TAX
PRINT “THE TOTAL AMOUNT TO BE PAID IS”;TOTPAID
END

Rewrite the following program statements after rectifying the errors in


them.

a. PRINT ‘THE SUM IS’;SUM$


Ans :PRINT “THE SUM IS”;SUM

b. LET 78=A
Ans :LET A=78

c. LET C=APPLE
Ans: LET C$= “APPLE”
d. 10 LET B$=(A+C)(Y-P)
Ans: 10 LET B=(A+C)*(Y-P)

e. LET “THE AGE IS”:A$


Ans: PRINT “THE AGE IS”;A

Sample Programs using the INPUT command:

Write a program to input two numbers and display their sum.


INPUT “ENTER TWO NUMBERS”; A,B
LET SUM=A+B
PRINT “THE SUM IS”; SUM
END

Write a program to input the length and breadth of a rectangle and display
its area and perimeter.

INPUT “ENTER THE LENGTH AND BREADTH”; L,B


LET AREA=L*B
LET PERI=2*(L+B)
PRINT “THE AREA IS”; AREA
PRINT “THE PERIMETER IS”; PERI
END

Write a program in BASIC to input three numbers and display the sum of
their cubes.
INPUT “ENTER THREE NUMBERS”; A,B,C
LET R=(A^3)+(B^3)+(C^3)
PRINT “THE RESULT IS”; R
END

Answers :

Check your progress 1:

Consider the following code:

LET X=23

LET Y=32

LET NAME$= “ENID BLYTON”

LET SUM=X+Y

Can you figure out the following?

a) How many numeric variables have been used in the above code?
4 variables.
X, Y, NAME$ and SUM.
b) What kind of variable is NAME$ ?
NAME$ is a string/alphanumeric variable.
c) What will be the value stored in the variable SUM?
SUM will store 32+23 i.e. 55.

Check your progress 2:

Consider the following code and answer the given questions:


INPUT “ENTER A NUMBER”; P

INPUT “ENTER ANOTHER NUMBER”; Q

LET R=(P+Q)/2

PRINT R

END

Questions:

a) When will we input the values of P and Q?


The values of P and Q will be inputted after running the program.

b) What will be the output if we input the values of P and Q as 10 and 20?
The output will be (10+20)/2 i.e. 15

Check your progress 3:

Identify the following variables as Numeric, String or Invalid.

a. AB NUMERIC
b. AB$ STRING
c. 7JH INVALID
d. GARGI90 NUMERIC
e. DIJ# NUMERIC
f. K$$ INVALID
g. AVIRAJ! NUMERIC
h. MUN@ INVALID
i. K#P INVALID
j. KP# NUMERIC
k. DGY#$ INVALID
l. ER45TP NUMERIC
m. Y_U INVALID
n. V98 NUMERIC
o. G7H9 NUMERIC
p. DEEP87$ STRING
q. ARUN IS GOOD INVALID
----x----x----

You might also like