Class 6 Basic Programming
Class 6 Basic Programming
Variable
Depending on the type ofvalue or data stored, variables are of two types.
Numeric Variable
The variable that holds a numeric value for arithmetic calculations is called
numeric variable.
String Variable
e.g.
LET X=23
LET Y=32
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?
LET
Eg.
LET P=20
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 AGE=12
END
OUTPUT:
INPUT
This command allows the user to enter a value for the variable while running
the program.
e.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.
LET R=(P+Q)/2
PRINT R
END
Questions:
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
END
LET P = 25
LET A = TOT – P
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
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
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)
Write a program to input the length and breadth of a rectangle and display
its area and perimeter.
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 :
LET X=23
LET Y=32
LET SUM=X+Y
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.
LET R=(P+Q)/2
PRINT R
END
Questions:
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
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----