Wednesday, May 29

Reading and Printing

Introduction

In a computer program it is often necessary to supply data to the program and print the result. This is done by input and output statements. In a BASIC program data can be supplied by INPUT, READ,DATA, RESTORE statements and printed with PRINT and LNPRINT statement.
PRINT Statement
The PRINT statement is used to output a display on the screen.
Syntax
LN PRINT [list of expression] [;] 
? [list of expression] [;] 
where,
LN  :  Line Number
list of expressions  :  value of expressions which is to be displayed
Points to Remember :

  • if list of expression is omitted , blank line is displayed.
  • if list of expression is included , values of expression are displayed.
  • Expression in the list may be numeric and / or string expressions, separated by comma or semicolons.
  • String constant in the list must be enclosed in double question marks.
  • ? (question mark) may be used in place of the word PRINT.
Example 1
Follwing are some valid PRINT statements :
1. 5 PRINT A
2. 10 PRINT 
3. 15 PRINT A+B, C
4. 20 PRINT "C, " , C, " A+B"; T
5. 25 PRINT A $+ B $, C $
6. 30 PRINT {28.34 - 11.28}^9*(1.5 E5)

Use of PRINT statement in the programs
CS 5.1 Display on the screen for PRINT statement

Ok
LIST
10   REM Learning the use of PRINT statement
20   REM  Values of two numbers X and Y
30   X=20
40   Y=10
50   REM Addition of two numbers X and Y
60   A=X+Y
70   PRINT X
80   PRINT Y
90   PRINT A
100 END
Ok
RUN
20
10 
30
Ok

CS 5.2 Dislpay on the screen for PRINT statement

Ok
LIST
10  REM Learning the use of PRINT statement
20  REM Values of the numbers X and Y
30  X=20
40  Y=10
50  REM Addition of two numbers X and Y
60  A=X+Y
70  PRINT "Value of X ="; X
80  PRINT " Value of Y="; Y
90  PRINT "Addition of X and Y ="; A
100 END
Ok
RUN
Value of X = 20
Value of Y = 10
Addition of X and Y = 30
Ok    
        
              
 
    

No comments:

Post a Comment