QBASIC PROGRAM TO FIND TOTAL NO. OF R AND S IN A STRING
CLS
INPUT "ENTER ANY STRING"; S$
RC = 0
SC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ = "R" THEN RC = RC + 1
IF C$ = "S" THEN SC = SC + 1
NEXT I
PRINT "TOTAL NO. OF R= "; RC
PRINT "TOTAL NO. OF S= "; SC
END
USING SUB
DECLARE SUB RSCOUNT(S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL RSCOUNT(S$)
END
SUB RSCOUNT(S$)
RC = 0
SC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ = "R" THEN RC = RC + 1
IF C$ = "S" THEN SC = SC + 1
NEXT I
PRINT "TOTAL NO. OF R= "; RC
PRINT "TOTAL NO. OF S= "; SC
END SUB
0 Comments