Monday, April 7 2025

Header Ads

Breaking News
recent

Input a string and print the number of vowels.

--------------------------------------------------------------------------------------------------------------------------
REM to input a string and count the number of the vowels
--------------------------------------------------------------------------------------------------------------------------
CLS
INPUT "Enter a string"; n$
FOR I = 1 TO LEN(n$)
    p$ = MID$(n$, I, 1)
    IF p$ = "a" OR p$ = "e" OR p$ = "i" OR p$ = "o" OR p$ = "u" THEN c = c + 1
NEXT I
PRINT "Number of vowels in string is:"; c
END
--------------------------------------------------------------------------------------------------------------------------
USING SUB PROCEDURE
--------------------------------------------------------------------------------------------------------------------------
DECLARE SUB vol()
CLS
CALL vol
END
SUB vol
INPUT "Enter a string"; n$
FOR I = 1 TO LEN(n$)
    p$ = MID$(n$, I, 1)
    IF p$ = "a" OR p$ = "e" OR p$ = "i" OR p$ = "o" OR p$ = "u" THEN c = c + 1
NEXT I
PRINT "Number of vowels in string is:"; c
END SUB
--------------------------------------------------------------------------------------------------------------------------
USING FUNCTION PROCEDURE
--------------------------------------------------------------------------------------------------------------------------
DECLARE FUNCTION vol(n$)
REM TO COUNT Number Of VOWELS IN STRING
CLS
INPUT "Enter a string"; n$
PRINT "Number of vowel in string is:"; vol(n$)
END
FUNCTION vol (n$)
FOR I = 1 TO LEN(n$)
    p$ = MID$(n$, I, 1)
    IF p$ = "a" OR p$ = "e" OR p$ = "i" OR p$ = "o" OR p$ = "u" THEN c = c + 1
NEXT I
vol = c
END FUNCTION
--------------------------------------------------------------------------------------------------------------------------

No comments:

Powered by Blogger.