BASIC
Constant :
Value which does
not change.
There are two
types :
1.
Numeric
Constant
2.
String
Constant
Numeric constant
Numbers
negative, positive, decimal or whole numbers.
Example :
-5
1345
78.12
String Constant
This is also
called Alphanumeric constant. It consists of numbers or alphabets or special
characters ,it is written within double
quotes(“ “).
Example :
“Cottons”
“Bangalore”
“Exam March
2014”
Variable
1.
Numeric
Variable
2.
String
Variable
Numeric
Variable:
A variable that
holds the numeric constant.
Example :
A
X1
XY
String variable
The variable
that holds the alphanumeric constant. This cannot be used for arithmetic
calculations. This variable must end
with a $ sign.
String
Variable
|
String
Constant
|
Must end with $
|
Must be enclosed within “ “
|
Eg: a$, name$,
xy$
|
Eg: a, xy
|
Operators
·
Arithmetic
Operators
·
Relational
Operators
·
Logical
Operators
Arithmetic
Operators : We are going to use all the
following operators in our program, for example multiplication is *(asterisk) not x as we use in Maths.
Addition +
Subtraction -
Multiplication *
Division /
Exponential ^
Relational
Operators: They are used to perform comparisons.The relational operators will
give TRUE or FALSE after comparision.
Less than <
Greater than >
Less than or
equal to <=
Greater than or
equal to >=
Equal to =
Not equal to < >
Logical
Operators: They are also called Boolean Operators.
·
AND
·
OR
·
NOT
Let us see how
the logical operator works.
Imagine a
condition for getting a scholarship, either you should score above 90 in
Computer science or above 80 in Maths. Assume that you have scored 85 in
Computers but 87 in Maths. It is very clear that you will get the scholarship.
Computer Science (C)
|
Maths (M)
|
Result (C>90) OR (M >80)
|
95
|
63
|
True
|
71
|
81
|
True
|
95
|
100
|
True
|
46
|
52
|
False
|
The second
condition is you should score above 90 in Computer science and above 80 in
Maths.
Computer Science (C)
|
Maths (M)
|
Result (C>90) AND (M >80)
|
95
|
63
|
False
|
71
|
81
|
False
|
95
|
100
|
True
|
46
|
52
|
False
|
1. Print
Command:
It is used to
display the output on the screen.
Example:
Print “Hi I am in Class 6”
Print 20 *5
The first command is within the quotes since it
is a string constant. The second command calculates the expression and gives
the answer 100
Print with comma
Print with
semicolon
Print with Colon
Empty Print - This gives an empty line.
INPUT
It accepts the
values from the user through the keyboard.
Difference
between LET and INPUT is :
If we are using
LET command the values of the program remains the same, therefore whenever we execute(RUN)
the program, the output remains the same.
If we are using
INPUT command, different values can be given each time we execute the program.
To accept a
number:
Input A
To accept a
string:
Input A$
1. Write
a program to enter the side and calculate the area of a square.
(Area of square= side x side)
Print
“Enter the side”
Input
S
Let
area= S * S
Print
area
End
Note :
Print "Enter the side" and Input S can be combined into a single statement.
Input "Enter the side" ; S
2. Write a program to find the area of a rectangle.
( Area of rectangle= Length X Breadth)
Print “Enter Length and breadth”
Input
L, B
Let
A=L * B
Print
A
End
3.
Write a program to enter 2 numbers and display the sum, difference,
multiplication and division
Print
“Enter 2 Numbers”
Input
a,b
Let
s=a+b
Let
diff=a – b
Let
M=a*b
Let
D=a/b
Print
“Sum=” ;s
Print
“Difference=”;diff
Print
“Product=”; M
Print
“Division=”; D
end
Conditional
statements
This will
execute the statements based on a given condition. Computer cannot take any
decision , so we should instruct the computer to take some action based on the
condition given by the user.
·
If
Then
·
If
then else
IF THEN ELSE
Syntax:
If condition
then
Statement 1
Else
Statement 2
End if
1.
Write
a program to enter a number check whether it is positive or negative.
(A
number is said to be positive if it is greater than 0 otherwise it is negative)
Print
“Enter a number”
Input
N
If
N > 0 then
Print
“Positive”
Else
Print
“Negative”
End
if
End
2.
Input
two numbers and display the biggest number.
Print
“Enter two numbers”
Input
a, b
If
a>b then
Print
a “is big”
Else
Print b “is big”
End
if
End3. If the mark entered is below 45, then you should print Fail otherwise print Pass.
Input "Enter your mark " ; M
If M > = 45 then
Print "Pass "
Else
Print "Fail"
End if
End
No comments:
Post a Comment