QBasic programs collection-Especially for SEE (Grade-10)
QBasic program to know the output of program using dry run table- to find the sum of numbers between 1 and 20 and which are divisible by 4, using sub procedure
declare sub sum(A)
A = 2
Call sum(A)
End
Sub sum (A)
While A <= 20
If A Mod 4 = 0 Then
s = s + A
End If
A = A + 1
Wend
Print s
End Sub
Dry run table
A |
While
A<=20 |
If A Mod 4 = 0 |
S=s+A |
A=A+1 |
2 |
yes |
no |
|
A=3 |
3 |
yes |
no |
|
A=4 |
4 |
yes |
yes |
S=s+A=0+4=4 |
A=5 |
5 |
yes |
no |
|
A=6 |
6 |
yes |
no |
|
A=7 |
7 |
yes |
no |
|
A=8 |
8 |
y |
yes |
S=4+8=12 |
A=9 |
9 |
yes |
n |
|
=10 |
10 |
yes |
n |
|
=11 |
11 |
yes |
N |
|
=12 |
12 |
yes |
y |
=12+12=24 |
A=13 |
13 |
yes |
n |
|
=14 |
14 |
yes |
n |
|
=15 |
15 |
yes |
n |
|
=16 |
16 |
yes |
y |
=24+16=40 |
=17 |
17 |
yes |
n |
|
=18 |
18 |
yes |
n |
|
=19 |
19 |
yes |
n |
|
=20 |
20 |
yes |
y |
=40+20=60 |
21 |
21 |
no |
|
|
|
No comments:
Post a Comment