QBasic Programming

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

CLS
INPUT "ENTER ANY STRING"; S$
WC = 1
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
IF B$ = " " THEN
WC = WC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF WORDS= "; WC
END SUB

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

SUB COUNT (S$)
WC = 1
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
IF B$ = " " THEN
WC = WC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF WORDS= "; WC
END SUB

USING FUNCTION PROCEDURE

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

FUNCTION COUNT (S$)
WC = 1
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
IF B$ = " " THEN
WC = WC + 1
END IF
NEXT I
COUNT = WC
END FUNCTION

WAP to input any word and count total no. of vowels and consonants (Prev Lesson)
(Next Lesson) WAP to input any string and count total no. of vowels , consonants and words
Back to QBasic Programming

No Comments

Post a Reply

Course Curriculum

error: Content is protected !!