4) COUNT Total numbers of words in a sentence.(function)
DECLARE FUNCTION COUNT (A$)
CLS
INPUT " Enter a sentence"; A$
PRINT " Total no. of words ="; COUNT (A$)
END
FUNCTION COUNT(A$)
C = 0
FOR I = 1 TO LEN (A$)
B$ = MID$ (A$, I, 1)
C$ = UCASE$ (B$)
IF B$ =" " THEN C = C + 1
NEXT I
COUNT = C
END FUNCTION
0 comments