QBasic Programming

WAP to input any string and count total no. of consonants

CLS
INPUT "ENTER ANY STRING"; S$
CC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ <> "A" AND C$ <> "E" AND C$ <> "I" AND C$ <> "O"
AND C$ <> "U" AND C$ <> " " AND C$ <> "." THEN
CC = CC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF CONSONANTS= "; CC
END SUB

USING SUB PROCEDURE

DECLARE SUB COUNT (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL COUNT(S$)
END

SUB COUNT (S$)
CC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ <> "A" AND C$ <> "E" AND C$ <> "I" AND C$ <> "O"
AND C$ <> "U" AND C$ <> " " AND C$ <> "." THEN
CC = CC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF CONSONANTS= "; CC
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION COUNT (S$)
CLS
INPUT "ENTER ANY STRING"; S$
PRINT "TOTAL NO. OF CONSONANTS= "; COUNT(S$)
END

FUNCTION COUNT (S$)
CC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ <> "A" AND C$ <> "E" AND C$ <> "I" AND C$ <> "O" AND C$ <> "U" AND C$ <> " " AND C$ <> "." THEN
CC = CC + 1
END IF
NEXT I
COUNT = CC
END FUNCTION

WAP to input any string and display only vowels (Prev Lesson)
(Next Lesson) WAP to input any string and display only consonants
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!