Qbasic example programs output with dry run in table.

 

Write down the output of the given program. Show with dry run in table.

SEE (Supplementary/Upgrade) 2075 (2019)
DECLARE FUNCTION SUM (a) CLS a = 9 PRINT SUM (a) END FUNCTION SUM (a) FOR K = 1 TO a IF K MOD 2 = O THEN S = S + K END IF NEXT K SUM = S END FUNCTION
Answer:
Dry Run:
FOR K= 1 to a(9)K MOD 2 = 0S=S+K
1No-
2YesS=0+2=2
3No-
4YesS=2+4=6
5No-
6YesS=6+6=12
7No-
8YesS=12+8=20
9No-
∴ Final Output is : 20

2. Write down the output of the given program. Show with dry run in table.

SEE 2075 (2019) Province-2 

DECLARE FUNCTION SQD(N) CLS S = 0 FOR L = 1 TO 3 READ NUM S = S +SQD (NUM) NEXT L PRINT " Sum" ; S DATA 2,4,6 END FUNCTION SQD (N) SQD = N^2 END FUNCTION

Answer:
Dry Run:
LNSQD=N^2S=S+SQD(NUM)
1N=2SQD=2*2=4S=0+4=4
2N=4SQD=4*4=16S=4+16=20
3N=6SQD=6*6=36S=20+36=56
∴ Final Output is : Sum 56 

3. Write down the output of the given program. Show with dry run in table.

SEE 2075 (2019)

DECLARE SUB series ( ) CALL series END SUB series X = 1 FOR K = 1 TO 4 PRINT X; X = X + K NEXT K END SUB

Answer:
Dry Run:
XKPrint X;X=X+K
111X=1+1=2
222X=2+2=4
434X=4+3=7
747X=7+4=11
∴ Final Output is : 1 2 4 7

4. Write down the output of the given program. Show with dry run in table.

SEE 2074 (2018)

DECLARE SUB Display (T$) CLS T$ = "COMPUTER" CALL Display (T$) END SUB Display (T$) FOR C = 1 TO LEN (T$) STEP 2 D$ = MID$ (T$, C, 1) PRINT D$; NEXT C END SUB

5. Write down the output of the given program. Show with dry run in table.

DECLARE SUB PATTERN() CALL PATTERN END SUB PATTERN A=2 FOR I = 1 TO 5 PRINT A; A=A+2 NEXT I END SUB

Answer:
Dry Run:
AFOR I= 1 to 5Print A;A=A+2
212A=2+2=4
424A=4+2=6
636A=6+2=8
848A=8+2=10
10510A=10+2=12
∴ Final Output is
2 4 6 8 10

6. Write down the output of the given program. Show with dry run in table.

DECLARE SUB PATTERN() CALL PATTERN END SUB PATTERN FOR I = 1 TO 5 FOR J= 1 TO I PRINT J; NEXT J PRINT NEXT I END SUB
Answer:
Dry Run:-
IJ= 1 to IPrint J;
11-11
21-212
31-3123
41-41234
51-512345
∴Final output is  1 12 123 1234 12345

7. Write down the output of the given program. Show with dry run in table.

DECLARE SUB RESULT() CALL RESULT END SUB RESULT() N=5 C=1 WHILE C<=5 PRINT N N=N*10+5 C=C+1 WEND END SUB
Answer:
Dry Run:-
NCC<=5?PRINT NN=N*10+5C=C+1
511<=5? YES5N=5*10+5
=55
C=1+1=2
5522<=5? YES55N=55*10+5
=555
C=2+1=3
55533<=5? YES555N=555*10+5
=5555
C=3+1=4
555544<=5? YES5555N=5555*10+5=55555C=4+1=5
5555555<=5? YES55555N=55555*10+5
=555555
C=5+1=6
∴Final Output is:  5 55 555 5555 55555

8. Write down the output of the given program. Show with dry run in table.

DECLARE SUB SHOW (A) 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
Answer:
Dry Run:- N=87
A=87
B= A MOD 6 + 3B MOD 4=0?PRINT B; A=A-10A>=50?
B=87 MOD 6 + 3
=3+3=6
6 MOD 4 =0? (NO)6A=87-10=7777>=50? Y
B=77 MOD 6 + 3 
=5+3=8
8 MOD 4=0? YESA=77-10=6767>=50? Y
B=67 MOD 6 
=1+3=4
4 MOD 4=0? YESA=67-10=5757>=50? Y
B=57 MOD 6 
= 3+3=6
6 MOD 4=0? NO6A=57-10=4747>=50? NO
∴Final Output is:
6   6

9. Write down the output of the given program. Show with dry run in table.

DECLARE SUB 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
Answer:
Dry Run:
N=135
A=135
A<>0?R= A MOD 10T=T+RA=A\10PRINT T
135<>0? YESR= 135 MOD 10=5T=0+5=5A=135\10=13-
13<>0? YESR=13 MOD 10=3T=5+3=8A=13\10=1-
1<>0? YESR= 1 MOD 10=1T=8+1=9A=0-
0<>0? NO---9
∴Final Output is
9

10.Write down the output of the given program. Show with dry run in table.

DECLARE SUB REMINDER (R) CLS FOR I = 1 TO 4 READ X CALL REMINDER (X) NEXT I DATA 56,28,8,48 END SUB REMINDER (R) R1 = R MOD 4 R2 = R MOD 3 IF R1 = 0 AND R2<> 0 THEN PRINT R END IF END SUB
Answer:
Dry Run:
XRR1=R MOD 4R2=R MOD 3R1=0 AND R2<>0PRINT R
5656R1 = 0R2=2YES56
2828R1=0R2=1YES28
88R1=0R2=2YES8
4848R1=0R2=0NO-
∴Final output is:
56 28 8

11.Write down the output of the given program. Show with dry run in table.

DECLARE SUB show(abc$) CLS abc$ = "ZHTUOMENXSA" CALL show(abc$) END SUB show(abc$) Y = 48 FOR I = 1 TO 5 N = Y MOD 7 PRINT MID$(abc$,n,1); Y = Y - 1 NEXT I END SUB
Answer:
Dry Run:
YIN=Y MOD 7Print MID$(abc$,N,1);Y=Y-1
4816M47
4725O46
4634U45
4543T44
4452H43
∴Final output is: MOUTH

12.Write down the output of the given program. Show with dry run in table.

DECLARE SUB ABC() CALL ABC END SUB ABC N = 10 C = 1 D = 5 WHILE C<=5 PRINT N N = N + D C = C + 1 D = D + 5 WEND END SUB
Answer:
Dry Run:
NCWHILE N<=5?Print NN=N+DC=C+1D=D+5
101YES1010+5=1525+5=10
152YES1515+10=25310+5=15
253YES2525+15=40415+5=20
404YES4040+20=60520+5=25
605YES6060+25=856-
∴Final output is:  10 15 25 40 60

13.Write down the output of the given program. Show with dry run in table.

DECLARE SUB RESULT() CALL result END SUB result () FOR I = 1 TO 4 FOR J = 1 TO 5 PRINT (I + J) * 10 ; NEXT J PRINT NEXT I END SUB
Answer:
Dry Run:
Outer Loop Inner Loop OUTPUT 
IJ(I+J)*10
11-5(1+1)*10=20 
(1+2)*10=30
(1+3)*10=40 
(1+4)*10=50 
(1+5)*10=60 
21-5(2+1)*10=30 
(2+2)*10=40
(2+3)*10=50 
(2+4)*10=60 
(2+5)*10=70 
31-5(3+1)*10=40 
(3+2)*10=50
(3+3)*10=60 
(3+4)*10=70 
(3+5)*10=80 
41-5(4+1)*10=50 
(4+2)*10=60
(4+3)*10=70 
(4+4)*10=80 
(4+5)*10=90 
∴Final output is:  20 30 40 50 60 30 40 50 60 70 40 50 60 70 80 50 60 70 80 90

14. Write down the output of the given program. Show with dry run in table.

DECLARE FUNCTION NUMPRO(A AS INTEGER, B AS INTEGER) DIM N, M, S AS INTEGER CLS DATA 2,5 READ M%,N% S = NUMPRO(N%, M%) PRINT "Sum of all the values is";S END FUNCTION NUMPRO(A AS INTEGER,B AS INTEGER) S = 0 FOR C=1 TO A% PRINT C*B% S = S + C * B% NEXT C NUMPRO=S END FUNCTION
Answer:
Dry Run:
A=N=5
B=M=2
Counter Loop OUTPUT 
CC*B%S=S+C*B%
11*2=2S=0+1*2=2
22*2=4S=2+2*2=6
33*2=6S=6+3*2=12
44*2=8S=12+4*2=20
55*2=10S=20+5*2=30
∴Final output is:  2 4 6 8 10 Sum of all the values is 30
Netra Koirala

Netra Koirala

Computer Science Educator

Passionate computer science educator and author. Provides free study notes, practical guides, and tutorials for Class 9, 10, 11, 12, and B.Sc CSIT students in Nepal. Years of teaching experience in computer science fundamentals.

Computer Science notes, tutorials, MCQs, and educational resources for Nepal students. Covering Class 9, SEE preparation, Class 11, Class 12, SLC, programming, DBMS, networking, HTML, JavaScript, PHP, OOP and more.

Featured Post

Grade 10 Computer Science: Specification Grid & Model Questions

Specification Grid & Model Questions of Computer Science | Grade 10 📚 Examination Resource Specification Grid & M...

Followers