Site pages
Current course
Participants
General
Topic 1
Topic 2
Topic 3
Topic 4
Topic 5
Topic 6
Topic 7
Topic 8
Topic 9
Topic 10
Topic 11
Topic 12
Topic 13
Topic 14
Topic 15
Topic 16
Topic 17
Topic 18
Topic 19
Topic 20
Topic 21
Topic 22
Topic 23
Topic 24
Topic 25
Topic 26
Topic 27
Topic 28
Topic 29
Topic 30
Topic 31
Topic 32
Topic 33
Topic 34
Topic 35
Subscripted Variable:
Subscripted variables are used to store the values of the same type in an array. It also helps us to store more values in a single variable name. Subscripted variables are declared by giving the variable name along with the subscript. Example: a(10) Here a is the variable name and 10 is known as the subscripted value through which we can store 10 values in the variable name a. The 10 values are stored in a(1),a(2),….,a(10). As only one subscript is given for the above variable, the array is called as the single dimensional array. Program Given the number 20,13,-14,11,50,16,-17,18,19,2. Store them in the computer memory. Read a number from the terminal. Verify if this number is present in the above list when the range of a loop lies within the range of another loop, the first loop is said to be nester in the latter. The loops may be placed as The loops may also be specified as Program Develop a program to calculate the sum 10 REM TO ILLUSTRATE NESTING OF LOOPS 20 PRINT “J”,”SUM” 30 PRINT 40 REM FIRST LOOP STARTS 50 FOR J = 1 TO 5 60 S=0 70 REM SECOND LOOP STARTS 80 FOR K=1 TO 5 90 S = S+K^J 100 NEXT K 110 T=0 120 REM THIRD LOOP STARTS 130 FOR K=1 TO 5 140 T = T+K*J 150 NEXT K 160 Q=S+T 170 PRINT J,Q 180 NEXT J 190 END Output J SUM 1 30 2 85 3 270 4 1039 5 4500 Where test-condition --is relational or Boolean expression whose value may be true or false S1,S2,… -- are BASIC statements Each WHILE must have its corresponding DO statement. The action of WHILE –DO statement is as follows. Execute statement S1, S2, … up to DO ,as long as the test-condition is true. When it becomes false, execute statement following DO. Thus the execution of WHILE-DO statement is completed only when the test-condition becomes false. Program: 10 REM ACTION OF WHILE –DO STATEMENT 20 LET SUM = 0 30 LET I= 1 40 WHILE I<=10 50 SUM =SUM + I 60 I = I+1 70 DO 80 PRINT “SUM=”;SUM 90 END |
Last modified: Wednesday, 18 January 2012, 10:59 PM