QBasic programs collection-Especially for SEE (Grade-10)
QBasic program to know the output of program using dry run table(p-2)
declare function reverse$(s$)
Cls
Input "enter a string"; s$
Print "the reverse of a string is"; reverse(s$)
End
Function reverse$ (s$)
For i = Len(s$) To 1 Step -1
r$ = r$ + Mid$(s$, i, 1)
Next i
reverse$ = r$
End Function
Output with dry run table:
If the input is 'program' then its dry run can be
S$ |
For i=len(s$)
to 1 step-1 |
r$=r$+mid$(s$,I,1) |
|
program |
I=7 |
r$=m |
|
|
I=6 |
r$=m+a=ma |
|
|
I=5 |
R$=ma+r=mar |
|
|
I=4 |
r$=mar+g=marg |
|
|
I=3 |
r$=marg+o=margo |
|
|
I=2 |
r$=margo+r=margor |
|
|
I=1 |
r$=margor+p=margorp |
|
Output:
margorp
No comments:
Post a Comment