3.2.1. QBASIC Modular Programming Find Output With Dry Run Solutions - SEE COMPUTER SCIENCE 2080
1. Write the output of the given program: Show with dry run in table. [2]
DECLARE SUB SHOW(A)
CLS
N=87
CALL SHOW(N)
END
SUB SHOW(A)
DO
B=A MOD 6+3
IF B MOD 4=0 THEN GOTO AA
PRINT B;
AA:
A=A-10
LOOP WHILE A>=50
END SUB
Dry run table
N |
A |
B=A MOD 6 + 3 |
IS B MOD 4=0 ? |
PRINT B |
A=A-10 |
WHILE A>=50 |
87 |
87 |
87 MOD 6 + 3 =3 + 3 = 6 |
6 MOD 4=0 ? 2 = 0 No |
6 |
87-10=77 |
77>=50 YES |
|
77 |
77 MOD 6 + 3 5+3=8 |
8 MOD 4=0? 0=0 YES |
|
77-10=67 |
67>=50 YES |
|
67 |
67 MOD 6+3 1+3=4 |
4 MOD 4=0? 0=0 YES |
|
67-10=57 |
57>=50 YES |
|
57 |
57 MOD 6+3 3+3=6 |
6 MOD 4=0? 2=0 NO |
6 |
57-10=47 |
47>=50 NO Loop Exits |
|
47 |
|
|
|
|
|
The output of the program is:
6 6
2. Write
the output of the given program: (Workout with dry run) [2]
DECLARE FUNCTION OUTPUT1(A)
CLS
N=135
CALL OUTPUT1(N)
END
SUB OUTPUT1(A)
DO WHILE A < > 0
R = A MOD 10
T = T + R
A = A \ 10
LOOP
PRINT T
END SUB
Dry run Table
N |
A |
DO WHILE A < > 0 |
R=A MOD 10 |
T=T + R |
A=A\10 |
PRINT T |
135 |
135 |
135 < > 0 Yes |
135 MOD 10 = 5 |
0+5=5 |
135\10=13 |
9 |
|
13 |
13 < > 0 Yes |
13 MOD 10=3 |
5+3=8 |
13\10=1 |
|
|
1 |
1 < > 0 Yes |
1 MOD 10=1 |
8 + 1=9 |
1\10=0 |
|
|
0 |
0 < > 0 No Loop Exits |
|
|
|
|
The output of the program is:
9
3. Write down the output of the given programs.
[2]
DECLARE SUB DISPLAY (A)
CLS
A= 3
CALL DISPLAY (A)
END
SUB DISPLAY (A)
FOR X = 1 TO 6
PRINT A;
IF A MOD 2 = 0 THEN
A=A/2
ELSE
A= (A*3)+1
END IF
NEXT X
END SUB
Dry Run
A |
X=1 TO 6 |
PRINT A; |
IS A MOD 2=0 ? |
Yes (A=A/2) |
No(A=A*3+1)
|
3 |
1 To 6 Yes |
3 |
3 MOD 2=0 1=0 NO |
|
3*3+1=10 |
10 |
2 To 6 Yes |
10 |
10 MOD 2=0 0=0 YES |
10/2=5 |
|
5 |
3 To 6 Yes |
5 |
5 MOD 2=0 1=0 NO |
|
5*3+1=16 |
16 |
4 To 6 Yes |
16 |
16 MOD 2=0 0=0 YES |
16/2=8 |
|
8 |
5 To 6 |
8 |
8 MOD 2=0 0=0 YES |
8/2=4 |
|
4 |
6 To 6 |
4 |
4 MOD 2=0 0=0 YES |
4/2=2 |
|
2 |
7 To 7 No |
Loop terminates |
|
|
|
The output of the program is:
3 10
5 16 8
4
4. Write down the output of the given program.
Show with the dry run in table.
DECLARE SUB SERI ( )
CLS
CALL SERI
END
SUB SERI
A$ = "SCIENCE"
B = LEN (A$)
FOR I = 1 TO 4
PRINT TAB(I); MID$(A$, I, B)
B =B-2
NEXT I
END SUB
DRY RUN TABLE:
A$ |
B=LEN(A$) |
I=1 TO 4 |
PRINT TAB(I);MID$(A$, I,
B) |
B=B-2 |
SCIENCE |
7 |
1 |
SCIENCE |
7-2=5 |
|
5 |
2 |
CIENC |
5-2=3 |
|
3 |
3 |
IEN |
3-2=1 |
|
1 |
4 |
E |
1-2=-1 |
|
-1 |
5 |
LOOP EXITS |
|
The output of the
program is:
SCIENCE
CIENC
IEN
E
5. What will be output?
DECLARE
FUNCTION FACT (N)
CLS
N=5
PRINT
FACT (N)
END
FUNCTION
FACT (N)
F=1
FOR
I=1 TO N
F=F*I
NEXT
I
FACT=F
END FUNCTION
Dry Run
N |
F |
FOR I=1 to 5 |
F=F*I |
PRINT FACT(N) |
5 |
1 |
1 to 5Yes |
1*1=1 |
120 |
|
1 |
2 to 5 Yes |
1*2=2 |
|
|
2 |
3 to 5 Yes |
2*3=6 |
|
|
6 |
4 to 5 Yes |
6*4=24 |
|
|
24 |
5 to 5 Yes |
24*5=120 |
|
|
120 |
6 to 5 No LoopExits |
|
|
The output of the
program is:
120
6. Write the output of the given program:
(Workout with a dry run). 2
DECLARE SUB ABC(A)
CLS
A=2
CALL ABC(A)
END
SUB ABC(A)
FOR J= 1 TO 5
PRINT A;
A=A+3;
NEXT J
END SUB
Dry run
A |
J=1
to 5 |
PRINT
A |
A=A+3 |
2 |
1
to 5 Yes |
2 |
2+3=5 |
5 |
2
to 5 Yes |
5 |
5+3=8 |
8 |
3
to 5 Yes |
8 |
8+3=11 |
11 |
4
to 5 Yes |
11 |
11+3=14 |
14 |
5
to 5 Yes |
14 |
14+3=17 |
17 |
6
to 5 No (loop exits) |
|
|
The output of the
program is:
2 5 8 11 14
7. Write the output of the given program showing
the dry run table.
DECLARE SUB result ( )
CLS
CALL result
END
SUB result ( )
FOR I = 9 to 1 step -2
Sum = sum + i^2
NEXT i
END SUB
Dry Run
I = 9 to 1 step -2 |
Sum = sum + i^2 |
PRINT sum |
9 to 1 yes |
0 + 81=81 |
165 |
7 to 1 yes |
81 + 49 = 130 |
|
5 to 1 yes |
130 + 25 = 155 |
|
3 to 1 yes |
155 + 9 = 164 |
|
1 to 1 yes |
164 + 1 = 165 |
|
-1 to 1 no Loop Exits |
|
|
The output of the
program is:
165
8. Write down the output of the given program.
Show with dry run in table. 2
DECLARE SUB Result(C$)
C$=”COMPUTER”
CALL Result(C$)
END
SUB Result(C$)
FOR C=1 TO LEN(C$) STEP 2
M$=MID$(C$,C,1)
N$=N$+M$
NEXT C
END SUB
Dry run
C$ |
C=1 TO LEN(C$) STEP 2 |
M$=MID$(C$,C,1) |
N$ |
PRINT N$ |
COMPUTER |
1TO
8 step 2 Yes |
C |
C |
CMUE |
|
3
to 8 Yes |
M |
C
+ M =CM |
|
|
5
to 8 Yes |
U |
CM
+ U = CMU |
|
|
7
to 8 Yes |
E |
CMU+
E = CMUE |
|
|
9
to 8 No Loop
Exits |
|
|
The output of the
program is:
CMUE
9. Write down the
output of the given program:
DECLARE SUB Series(A)
CLS
A=20
CALL Series(A)
END
SUB Series(A)
FOR K=1 to 5
PRINT A;
A=A+10
NEXT K
END SUB
Dry run
A |
K=1 to 5 |
PRINT A |
A=A+10 |
20 |
1 to 5 yes |
20 |
20+10=30 |
30 |
2 to 5 yes |
30 |
30+10=40 |
40 |
3 to 5 yes |
40 |
40+10=50 |
50 |
4 to 5 yes |
50 |
50+10=60 |
60 |
5 to 5 yes |
60 |
60+10=70 |
70 |
6 to 5 no Loop exits |
|
|
The output of the
program is:
20 30 40 50 60
10. Write down the output of the given
program. Show with dry run in
table.
[2]
DECLARE SUB Num ( )
CLS
CALL Num
END
SUB Num
N=2
A=5
C=1
WHILE C <= 9
PRINT N
N=N*3+A
A=A-1
C=C+2
WEND
END SUB
Dry Run
N |
A |
C |
C < = 9 |
PRINT N |
N=N*3+A |
A=A-1 |
C=C+2 |
2 |
5 |
1 |
1 < = 9 Yes |
2 |
2*3+5=11 |
5-1=4 |
1+2=3 |
11 |
4 |
3 |
3 < = 9 Yes |
11 |
11*3+4=37 |
4-1=3 |
3+2=5 |
37 |
3 |
5 |
5 < = 9Yes |
37 |
37*3+3=114 |
3-1=2 |
5+2=7 |
114 |
1 |
7 |
7 < = 9 Yes |
114 |
114*3+2=343 |
2-1=1 |
7+2=9 |
343 |
0 |
9 |
9 < = 9 Yes |
343 |
343*3+1=1029 |
1-1=0 |
9+2=11 |
1029 |
-1 |
11 |
11 < = 9 No Loop Exits |
|
|
|
|
The output of the
program is:
2
11
37
114
343
11. Write the output of the given
program showing the dry
table.
[2]
DECLARE SUB series()
CLS
CALL series
END
SUB series()
A=11111
C=5
WHILE C>=1
PRINT A;
A=A\10
C=C-1
WEND
END SUB
Dry Run
Variable |
Condition Check |
PRINT A; |
A=A\10 |
C=C-1 |
A |
C>=1 |
|
|
|
11111 |
5>=1 Yes |
11111 |
11111 \10=1111 |
5-1=4 |
1111 |
4>=1 Yes |
1111 |
1111\10=111 |
4-1=3 |
111 |
3>=1 Yes |
111 |
111\10=11 |
3-1=2 |
11 |
2>=1 Yes |
11 |
11\10=1 |
2-1=1 |
1 |
1>=1 Yes |
1 |
1\10=0 |
1-1=0 |
0 |
0>=1 No Loop Exits |
|
|
|
The output of the
program is:
11111 1111 111
11 1
12. Write the output of the following program.
Show dry run in table. [2]
DECLARE FUNCTION EXAM$(W$)
W$ = "COMPUTER"
PRINT EXAM$(W$)
FUNCTION EXAM$ (W$)
FOR P = 1 TO LEN(W$)
K$
= MID$(W$, P, 1)
IF
P MOD 2 = 0 THEN
K$
= LCASE$(K$)
ELSE
K$
= UCASE$(K$)
END
IF
S$
= S$ + K$
NEXT P
EXAM$ = S$
END FUNCTION
Dry Run
W$ |
P=1 to 8 |
K$= MID$(W$, P, 1) |
IS P MOD 2 = 0 |
Yes (K$ = LCASE$(K$) |
No (K$ = UCASE$(K$) |
S$ = S$ + K$ |
PRINT EXAM$(W$) |
COMPUTER |
1 to 8 Yes |
C |
1 MOD 2=0 1=0 No |
|
C |
C |
CoMpUtEr |
|
2 to 8 Yes |
O |
2 MOD 2 =0 0=0 Yes |
o |
|
Co |
|
|
3 to 8 Yes |
M |
3 MOD 2=0 1=0 No |
|
M |
CoM |
|
|
4 to 8 Yes |
P |
4 MOD 2 =0 0=0 Yes |
p |
|
CoMp |
|
|
5 to 8 Yes |
U |
5 MOD 2=0 1=0 No |
|
U |
CoMpU |
|
|
6 to 8 Yes |
T |
6 MOD 2 =0 0=0 Yes |
t |
|
CoMpUt |
|
|
7 to 8 Yes |
E |
7 MOD 2=0 1=0 No |
|
E |
CoMpUtE |
|
|
8 to 8 Yes |
R |
8 MOD 2 =0 0=0 Yes |
r |
|
CoMpUtEr |
|
|
9 to 8 No Loop Exits |
|
|
|
|
|
|
The output of the
program is:
CoMpUtEr
13. Write down the output of the given
program. Show with dry run in table.
DECLARE SUB SERIES ()
CLS
CALL SERIES
END
SUB SERIES ( )
X=1
Y=2
FOR P 1 TO 10
PRINT X:
X=X+Y
Y=Y+1
NEXT P
END SUB
Dry run
X |
Y |
P=1 TO 10 |
PRINT X: |
X=X+Y |
Y=Y+1 |
1 |
2 |
1 TO 10 Yes |
1 |
1+2=3 |
2+1=3 |
3 |
3 |
2 TO 10 Yes |
3 |
3+3=6 |
3+1=4 |
6 |
4 |
3 TO 10 Yes |
6 |
6+4=10 |
4+1=5 |
10 |
5 |
4 TO 10 Yes |
10 |
10+5=15 |
5+1=6 |
15 |
6 |
5 TO 10 Yes |
15 |
15+6=21 |
6+1=7 |
21 |
7 |
6 TO 10 Yes |
21 |
21+7=28 |
7+1=8 |
28 |
8 |
7 TO 10 Yes |
28 |
28+8=36 |
8+1=9 |
36 |
9 |
8 TO 10 Yes |
36 |
36+9=45 |
9+1=10 |
45 |
10 |
9 TO 10 Yes |
45 |
45+10=55 |
10+1=11 |
55 |
11 |
10 TO 10 Yes |
55 |
55+11=66 |
11+1=12 |
66 |
12 |
11 TO 10 No Loop Exits |
|
|
|
The output of the
program is:
1
3 6 10 15 21 28 26 45 55
14. Write down the output of the given program
with dry run table. [2]
DECLARE SUB NUMBER ()
CLS
CALL NUMBER
END
SUB NUMBER
N=3:C=1
WHILE C<=5
PRINT
N
N=N*10+3
C=C+1
WEND
END SUB
Dry Run
N |
C |
C<=5 |
PRINT N |
N=N*10+3 |
C=C+1 |
3 |
1 |
1<=5 yes |
3 |
33 |
1+1=2 |
33 |
2 |
2<=5 yes |
33 |
333 |
2+1=3 |
333 |
3 |
3<=5 yes |
333 |
3333 |
3+1=4 |
3333 |
4 |
4<=5 yes |
3333 |
33333 |
4+1=5 |
33333 |
5 |
5<=5 yes |
33333 |
333333 |
5+1=6 |
|
6 |
6<=5 no (loop exits) |
|
|
|
The output of the
program is:
3
33
333
3333
33333
15. Write down the output of the given program.
Show with dry run in table .
DECLARE SUB SERI()
CLS
CALL SERI
END
SUB SERI
X# = 1
FOR I = 1 TO 5
PRINT X# * X#
X# = X# * 10 +1
NEXT I
END SUB
X# |
I = 1 TO 5 |
PRINT X# * X# |
X# = X# * 10 +1 |
1 |
1 to 5 ‘yes’ |
1 |
1*10+1=11 |
11 |
2 to 5 ‘yes’ |
121 |
11*10+1=111 |
111 |
3 to 5 ‘yes’ |
12321 |
111*10+1=1111 |
1111 |
4 to 5 ‘yes’ |
1234321 |
1111*10+1=11111 |
11111 |
5 to 5 ‘yes’ |
123454321 |
11111*10+1=111111 |
111111 |
6 to 5 ‘no’ |
|
|
|
Loop exits |
|
|
The output of the
program is:
1
121
12321
1234321
123454321
16. Write down the output of the given
program and show them in dry run table: [2]
DECLARE
SUB CITY (K$)
CLS
CALL
CITY ("KATHMANDU")
END
SUB
CITY (K$)
FOR
K = 1 TO LEN (K$)
C$
= MID$ (K$, K, 1)
IF
K MOD 2 = 1 THEN
C$
= UCASE$ (C$)
ELSE
C$
= LCASE$ (C$)
END
IF
X$
= X$ + C$
NEXT
K
PRINT
X$
END
SUB
DRY RUN
K$ |
K = 1 TO LEN (K$) |
C$ = MID$ (K$, K, 1) |
IS K MOD 2=1 |
Yes C$ = UCASE$ (C$) |
No C$ = LCASE$ (C$) |
X$ = X$ + C$ |
PRINT X$ |
KATHMANDU |
1 to 9 ‘yes’ |
K |
1 MOD 2=1 YES |
K |
|
K |
KaThMaNdU |
|
2 to 9 yes |
A |
2 MOD 2=1 NO |
|
a |
Ka |
|
|
3 to 9 yes |
T |
3 MOD 2=1 YES |
T |
|
KaT |
|
|
4 to 9 yes |
H |
4 MOD 2=1 NO |
|
h |
KaTh |
|
|
5 to 9 yes |
M |
5 MOD 2=1 YES |
M |
|
KaThM |
|
|
6 to 9 yes |
A |
6 MOD 2=1 NO |
|
a |
KaThMa |
|
|
7 to 9 yes |
N |
7 MOD 2=1 YES |
N |
|
KaThMaN |
|
|
8 to 9 yes |
D |
8 MOD 2=1 NO |
|
d |
KaThMaNd |
|
|
9 to 9 yes |
U |
9MOD 2=1 YES |
U |
|
KaThMaNdU |
|
|
10 to 9 no Loop exits |
|
|
|
|
|
|
OUTPUT
KaThMaNdU
17. FIND OUTPUT ALONG WITH DRY RUN
DECLARE SUB SERIES ( )
CLS
CALL SERIES
END
SUB SERIES
A$="NEPAL"
B=1
FOR I=1 TO LEN(A$) STEP 2
IF B < > 3 THEN
PRINT MID$(A$,B,I)
ELSE
PRINT MID$(A$,1,I)
END IF
B=B+1
NEXT I
END SUB
DRY RUN
A$ |
B |
1 TO 5 STEP 2 |
B< > 3 |
PRINT MID$(A$,B,I) |
NEPAL |
1 |
1 TO 5 YES |
1 < > 3 YES |
N |
|
2 |
3 TO 5 YES |
2 < > 3 YES |
EPA |
|
3 |
5 TO 5 YES |
3 < > 3 NO |
NEPAL |
|
4 |
7 TO 5 NO LOOP EXITS |
|
|
OUTPUT
N
EPA
NEPAL
18. Write down the output of the given
program. (2)
Show with dry run in table.
DECLARE SUB SERU ( )
CLS
CALL SERU
END
SUB SERU ()
X=2
C=1
WHILE C<=10
S=X^C
PRINT S;
C=C+1
WEND
END SUB
Dry Run
X |
WHILE C<=10 |
S=X^C |
PRINT S; |
C=C+1 |
2 |
1<=10 Yes |
2^1=2 |
2 |
1+1=2 |
|
2<=10 Yes |
2^2=4 |
4 |
2+1=3 |
|
3<=10 Yes |
2^3=4 |
8 |
3+1=4 |
|
4<=10 Yes |
2^4=4 |
16 |
4+1=5 |
|
5<=10 Yes |
2^5=4 |
32 |
5+1=6 |
|
6<=10 Yes |
2^6=4 |
64 |
6+1=7 |
|
7<=10 Yes |
2^7=4 |
128 |
7+1=8 |
|
8<=10 Yes |
2^8=4 |
256 |
8+1=9 |
|
9<=10 Yes |
2^9=4 |
512 |
9+1=10 |
|
10<=10 Yes |
2^10=4 |
1024 |
10+1=11 |
|
11<=10 No Loop Exits |
|
|
|
Output of the program is
2 4 8 16 32
64 128 256 512
1024
19. Write the output of the given program
showing the dry run table. (2)
DECLARE FUNCTION PRO(N)
CLS
A=2
FOR J=1 TO 5
X= PRO(A)
PRINT X
NEXT J
END
FUNCTION PRO(N)
N=N+2
PRO=N
END FUNCTION
Dry Run
A |
J=1 to 5 |
X= PRO(A) |
N |
N=N+2 |
PRO=N |
PRINT X |
2 |
1 to 5 yes |
X= PRO(2) |
2 |
2+2=4 |
PRO=4 |
4 |
|
2 to 5 yes |
X= PRO(4) |
4 |
4+2=6 |
PRO=6 |
6 |
|
3 to 5 yes |
X= PRO(6) |
6 |
6+2=8 |
PRO=8 |
8 |
|
4 to 5 yes |
X= PRO(8) |
8 |
8+2=10 |
PRO=10 |
10 |
|
5 to 5 yes |
X= PRO(10) |
10 |
10+2=12 |
PRO=12 |
12 |
|
6 to 5 no loop exits |
|
|
|
|
|
Output of the program is
4
6
8
10
12
20. Write down the output of the given program.
\Show with dry run in table.
(2)
DECLARE SUB PATTERN(SS)
CLS
B$="PROGRAM"
CALL PATTERN(B$)
END
SUB PATTERN(S$)
H=LEN(S$)
I=10
FOR J=1 TO H STEP 2
H=H-2
PRINT TAB(I); MID$(S$,J,H)
I=I+1
NEXT J
END SUB
B$ |
S$ |
H=LEN(S$) |
I |
J=1 to 7 step 2 |
PRINT TAB(I); MID$(S$,J,H) |
PROGRAM |
PROGRAM |
7 |
10 |
1 to 7 step 2 Yes |
MID$(S$,1,5) PROGR |
|
|
5 |
11 |
3 to 7 step 2 Yes |
MID$(S$,3,3) OGR |
|
|
3 |
12 |
5 to 7 step 2 Yes |
MID$(S$,5,1) G |
|
|
1 |
13 |
7 to 7 step 2 Yes |
MID$(S$,7,-1) - |
|
|
-1 |
14 |
9 to 7 step 2 No [Loop Exits] |
|
The output of the program is:
PROGR
OGR
G
21. Write the output of the given program.
Show with dry run in table. [2]
DECLARE SUB SERIES ( )
CALL SERIES
END
SUB SERIES
A = 1
FOR I = 1 TO 5
PRINT I * A
A = A+ (10 ^ I)
NEXT I
END SUB
Dry Run
A |
I=1 to 5 |
PRINT I * A |
A= A+ (10 ^ I) |
1 |
1 to 5 yes |
1*1 =1 |
1+(10^1)=11 |
11 |
2 to 5 yes |
2*11=22 |
11+(10^2)=111 |
111 |
3 to 5 yes |
3*111=333 |
111+(10^3)=1111 |
1111 |
4 to 5 yes |
4*1111=4444 |
1111+(10^4)=11111 |
11111 |
5 to 5 yes |
5*11111=55555 |
11111+(10^5)=111111 |
111111 |
6 to 5 no [Loop Exits] |
|
|
The output of the program is
1
22
333
4444
55555
22. Write down the output of the given
program.
[2]
DECLARE FUNCTION TEXT$(A$)
CLS
A$= “TECHNOLOGY”
Y$= TEXT$(A$)
PRINT Y$
END
FUNCTION TEXT$(A$)
B= LEN(A$)
FOR I = 1 TO B
IF I MOD 2 = 1 THEN
B$= B$+MID$(A$,I,1)
END IF
NEXT I
TEXT$= B$
END FUNCTION
Dry Run
A$ |
B |
I=1 to B |
IF I MOD 2 =1 |
B$=B$+MID$(A$,I,1) |
Y$ |
PRINT Y$ |
TECHNOLOGY |
10 |
1 to 10 |
1 MOD 2=1 1=1 yes |
T |
TCNLG |
TCNLG |
|
|
2 to 10 |
2 MOD 2=1 0=1 no |
|
|
|
|
|
3 to 10 |
3 MOD 2=1 1=1 yes |
T+C = TC |
|
|
|
|
4 to 10 |
4 MOD 2=1 0=1 no |
|
|
|
|
|
5 to 10 |
5 MOD 2=1 1=1 yes |
TC+N=TCN |
|
|
|
|
6 to 10 |
6 MOD 2=1 0=1 no |
|
|
|
|
|
7 to 10 |
7 MOD 2=1 1=1 yes |
TCN+L=TCNL |
|
|
|
|
8 to 10 |
8 MOD 2=1 0=1 no |
|
|
|
|
|
9 to 10 |
9 MOD 2=1 1=1 yes |
TCNL+G |
|
|
|
|
10 to 10 |
10 MOD 2=1 0=1 no |
TCNLG |
|
|
|
|
11 to 10 Loop Exit |
|
|
|
|
The output of the program is
TCNLG
23. Write down the output of the following along
with dry run table. 2
DECLARE SUB SENDUP(S$)
E$= “NPABSON"
CALL SENDUP(E$)
END
SUB SENDUP(S$)
FOR i = 1 to LEN(S$) STEP 1
IF i MOD 2<>0 THEN
EE$=EE$+LCASE$(MIDS(S$,I,1))
ELSE
EE$=EE$+UCASE$(MIDS(S$,I,1))
END IF
NEXT i
PRINT EE$
END SUB
Dry Run
E$ |
S$ |
i=1 to LEN(S$) |
i MOD 2 <>0 |
Yes EE$=EE$+LCASE$(MIDS(S$,I,1)) |
No EE$=EE$+UCASE$(MIDS(S$,I,1)) |
NPABSON |
NPABSON |
1 to 7 yes |
1 MOD 2 <>0 1<>0 Yes |
n |
n+P=nP |
|
|
2 to 7 yes |
2 MOD 2 <>0 0<>0 No |
|
|
|
|
3 to 7 yes |
3 MOD 2 <>0 1<>0 Yes |
nP+a nPa |
|
|
|
4 to 7 yes |
4 MOD 2 <>0 0<>0 No |
|
nPa+B nPaB |
|
|
5 to 7 yes |
5 MOD 2 <>0 1<>0 Yes |
nPaB+s nPaBs |
|
|
|
6 to 7 yes |
6 MOD 2 <>0 0<>0 No |
|
nPaBs+O nPaBsO |
|
|
7 to 7 yes |
7 MOD 2 <>0 1<>0 Yes |
nPaBsO+n nPaBsOn |
|
|
|
8 to 7 loop exits |
|
|
|
The output of the program is :
nPaBsOn
24. Write down the output of the following program
with dry run table.
DECLARE SUB REG(M,N$,T)
CLS
A=1
X$=”PABSON”
CALL REG(A,X$,T)
END
SUB REG(M,N$,T)
FOR I=LEN(N$) TO 1 STEP-1
PRINT MID$(N$,I,M)
M=M+1
NEXT I
END SUB
Dry Run
A |
X$ |
M |
T |
I=LEN(N$) TO 1 STEP-1 |
PRINT MID$(N$,I,M) |
M=M+1 |
1 |
PABSON |
1 |
0 |
6 TO 1 STEP-1 Yes |
MID$(PABSON,6,1) N |
1+1=2 |
|
|
2 |
|
5 TO 1 STEP -1 Yes |
MID$(PABSON,5,1) ON |
2+1=3 |
|
|
3 |
|
4 TO 1 STEP -1 Yes |
MID$(PABSON,4,1) SON |
3+1=4 |
|
|
4 |
|
3 TO 1 STEP -1 Yes |
MID$(PABSON,3,1) BSON |
4+1=5 |
|
|
5 |
|
2 TO 1 STEP -1 Yes |
MID$(PABSON,2,1) ABSON |
5+1=6 |
|
|
6 |
|
1 TO 1 STEP -1 Yes |
MID$(PABSON,1,1) PABSON |
6+1=7 |
|
|
7 |
|
0 TO 1 STEP -1 No Loop Exits |
|
|
The output of the program is :
N
ON
SON
BSON
ABSON
PABSON
25. Write down the output of the given program.
DECLARE SUB ptt()
CLS
CALL patt
END
SUB patt
X=1
FOR i=1 TO 5
PRINT X
X=(x*10)+i
NEXT i
END SUB
Dry Run
X |
I=1 to 5 |
PRINT X |
X=(x*10)+i |
1 |
1 to 5 Yes |
1 |
(1*10)+1 =11 |
|
2 to 5 Yes |
11 |
(11*10)+2 =112 |
|
3 to 5 Yes |
112 |
(112*10)+3 =1123 |
|
4 to 5 Yes |
1123 |
(1123*10)+4 11234 |
|
5 to 5 Yes |
11234 |
(11234*10)+5 112345 |
|
6 to 5 No Loop Exits |
|
|
The output of the program is :
1
11
112
1123
11234
26. Write down the output of the given program.
Show with dry run in table: [2]
DECLARE SUB SERIES(X)
CLS
X=7
CALL SERIES(X)
END
SUB SERIES(X)
FOR M = 1 TO 10
PRINT X;
IF X MOD 2=0 THEN
X=X/2
ELSE
X=3*X+1
END IF
NEXT M
END SUB
Dry Run
X |
M=1 to 10 |
PRINT X; |
X MOD 2=0 |
X=3*X+1 (No) |
X=X/2 (Yes) |
7 |
1 to 10 yes |
7 |
7 MOD 2=0 1=0 No |
X=3*X+1 =3*7+1=22 |
|
22 |
2 to 10 yes |
22 |
22 MOD 2=0 0=0 Yes |
|
=22/2 =11 |
11 |
3 to 10 yes |
11 |
11 MOD 2=0 1=0 No |
3*11+1=34 |
|
34 |
4 to 10 yes |
34 |
34 MOD 2=0 0=0 yes |
|
34/2=17 |
17 |
5 to 10 yes |
17 |
17 MOD 2=0 1=0 no |
3*17+1=52 |
|
52 |
6 to 10 yes |
52 |
52 MOD 2=0 0=0 Yes |
|
52/2=26 |
26 |
7 to 10 yes |
26 |
26 MOD 2=0 0=0 Yes |
|
26/2=13 |
13 |
8 to 10 yes |
13 |
13 MOD 2=0 1=0 No |
3*13+1=40 |
|
40 |
9 to 10 yes |
40 |
40 MOD 2=0 0=0 Yes |
|
40/2=20 |
20 |
10 to 10 yes |
20 |
20 MOD 2=0 0=0 Yes |
|
20/2=10 |
10 |
11 to 10 No Loop Exits |
|
|
|
|
The output of the program is:
7 22 11 34 17
52 26 13 40 20
5. Write the output of
the given program. Show with dry run in
table. 2
DECLARE SUB SERIES()
CLS
CALL SERIES
END
SUB SERIES( )
X#=11111
FOR I= 1 TO 5
PRINT X#^2
X# = (X# - 1) / 10
NEXT I
END SUB
Dry Run
X#=11111 |
I=1 to 5 |
PRINT X#^2 |
X#=(X#-1)/10 |
|
1 to 5 Yes |
123454321 |
(11111-1)/10=1111 |
1111 |
2 to 5 Yes |
1234321 |
(1111-1)/10=111 |
111 |
3 to 5 Yes |
12321 |
(111-1)/10=11 |
11 |
4 to 5 Yes |
121 |
(11-1)/10=1 |
1 |
5 to 5 Yes |
1 |
(1-1)/10=0 |
0 |
6 to 5 No Loop Exits |
|
|
The output of the program is:
123454321
1234321
12321
121
1
No comments:
Post a Comment