DECLARE FUNCTION REV$ (S$)
CLS
INPUT "ENTER ANY STRING"; S$
PRINT "REVERSED STRING IS "; REV$(S$)
END
FUNCTION REV$ (S$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
REV$ = W$
END FUNCTION
Write a program using
sub to get a word from the user and print the word in the reverse order.
DECLARE SUB REV (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL REV(S$)
END
SUB REV$ (S$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
PRINT "REVERSED STRING IS "; W$
END FUNCTION
Write a program using
FUNCTION….END FUNCTION to input a string and count the total number of
consonants.
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" THEN CC = CC + 1
NEXT I
COUNT = CC
END FUNCTION
Write a program to
find the numbers of vowels in an input string using ‘SUB…..END SUB’.
DECLARE SUB COUNT (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL COUNT(S$)
END
SUB COUNT (S$)
VC = 0
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ =
"I" OR C$ = "O" OR C$ = "U" THEN VC = VC + 1
NEXT I
PRINT "TOTAL NO. OF VOWELS= "; VC
END SUB
Write a program using
FUNCTION... END FUNCTION to count the number of words in a sentence.
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
NEXT I
COUNT = WC
END FUNCTION
Write a program to
declare SUB procedure to print only the vowels from a given word.
DECLARE SUB DISPV (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL DISPV(S$)
END
SUB DISPV(S$)
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ =
"I" OR C$ = "O" OR C$ = "U" THEN D$=D$+ B$
END IF
NEXT I
PRINT “VOWELS ONY ARE”; D$
END SUB
No comments:
Post a Comment