QBasic programs collection-Especially for SEE (Grade-10)
QBasic program to know the output of program using dry run table- to count total words.
declare function wordcount%(s$)
Cls
Input "enter a sentence", line$
Print "total words=", wordcount%(line$)
End
Function wordcount% (s$)
count = 1
For i = 1 To Len(s$)
If Mid$(s$, i, 1) = " " Then
count = count + 1
End If
Next i
wordcount% = count
End Function
output:
Dry run table for ouput is given below.
IF we take the input Hello how are you?,
S$
|
Count
|
I= 1 to
len(s$)[17]
|
Mid$(s$,I,1)=
“ “
|
|
Hello how
are you?
|
1
|
I=1
|
No upto
five times
|
|
|
|
I=6
|
Yes,
count=2
|
|
|
|
I=7/8/9
|
no
|
|
|
|
I=10
|
Yes,
count=3
|
|
|
|
I=11/12/13
|
no
|
|
|
|
I=14
|
Yes,count=4
|
|
|
|
I=15/16/17
|
no
|
|
output is
4