input any string and check whether the first character of a input string is alphabet, number or symbol.



233. WAP to input any string and check whether the first character of a input string is alphabet, number or symbol.
CLS
INPUT "ENTER ANY STRING"; S$
A$ = LEFT$(S$, 1)
B = ASC(A$)
IF B >= 48 AND B <= 57 THEN
CK$ = "FIRST CHARACTER IS A NUMBER"
ELSEIF B >= 65 AND B <= 90 OR B >= 97 AND B <= 122 THEN
CK$ = "FIRST CHARACTER IS ALPHABET"
ELSE
CK$ = "FIRST CHARACTER IS SYMBOL"
END IF
PRINT CK$
END SUB


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

SUB CHECK (S$)
A$ = LEFT$(S$, 1)
B = ASC(A$)
IF B >= 48 AND B <= 57 THEN
CK$ = "FIRST CHARACTER IS A NUMBER"
ELSEIF B >= 65 AND B <= 90 OR B >= 97 AND B <= 122 THEN
CK$ = "FIRST CHARACTER IS ALPHABET"
ELSE
CK$ = "FIRST CHARACTER IS SYMBOL"
END IF
PRINT CK$
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (S$)
CLS
INPUT "ENTER ANY STRING"; S$
PRINT CHECK$(S$)
END

FUNCTION CHECK$ (S$)
A$ = LEFT$(S$, 1)
B = ASC(A$)
IF B >= 48 AND B <= 57 THEN
CHECK$ = "FIRST CHARACTER IS A NUMBER"
ELSEIF B >= 65 AND B <= 90 OR B >= 97 AND B <= 122 THEN
CHECK$ = "FIRST CHARACTER IS ALPHABET"
ELSE
CHECK$ = "FIRST CHARACTER IS SYMBOL"
END IF
END FUNCTION

234. WAP to input any string and display only consonant by removing vowels.
CLS
INPUT "ENTER ANY STRING"; S$
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
W$=W$+B$
END IF
NEXT I
PRINT W$
END SUB

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

SUB DISP (S$)
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
W$=W$+B$
END IF
NEXT I
PRINT W$
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION DISP$ (S$)
CLS
INPUT "ENTER ANY STRING"; S$
PRINT DISP(S$)
END

FUNCTION DISP$ (S$)
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
W$=W$+B$
END IF
NEXT I
DISP$ =  W$
END FUNCTION

235. WAP to input string and find whether the first character is a number or uppercase or lowercase.
CLS
INPUT "ENTER ANY STRING"; S$
A$ = LEFT$(S$, 1)
B = ASC(A$)
IF B >= 48 AND B <= 57 THEN
CK$ = "FIRST CHARACTER IS A NUMBER"
ELSEIF B >= 65 AND B <= 90 THEN
CK$ = "FIRST CHARACTER IS UPPERCASE"
ELSE IF  B >= 97 AND B <= 122 THEN
CK$ = "FIRST CHARACTER IS LOWERCASE"
ELSE
CK$=”FIRST CHARACTER IS NEITHER NUMBER, UPPERCASE OR LOWERCASE”
END IF
PRINT CK$
END SUB


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

SUB CHECK (S$)
A$ = LEFT$(S$, 1)
B = ASC(A$)
IF B >= 48 AND B <= 57 THEN
CK$ = "FIRST CHARACTER IS A NUMBER"
ELSEIF B >= 65 AND B <= 90 THEN
CK$ = "FIRST CHARACTER IS UPPERCASE"
ELSE IF  B >= 97 AND B <= 122 THEN
CK$ = "FIRST CHARACTER IS LOWERCASE"
ELSE
CK$=”FIRST CHARACTER IS NEITHER NUMBER, UPPERCASE OR LOWERCASE”
END IF
PRINT CK$
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (S$)
CLS
INPUT "ENTER ANY STRING"; S$
PRINT CHECK$(S$)
END

FUNCTION CHECK$ (S$)
A$ = LEFT$(S$, 1)
B = ASC(A$)
IF B >= 48 AND B <= 57 THEN
CK$ = "FIRST CHARACTER IS A NUMBER"
ELSEIF B >= 65 AND B <= 90 THEN
CK$ = "FIRST CHARACTER IS UPPERCASE"
ELSE IF  B >= 97 AND B <= 122 THEN
CK$ = "FIRST CHARACTER IS LOWERCASE"
ELSE
CK$=”FIRST CHARACTER IS NEITHER NUMBER, UPPERCASE OR LOWERCASE”
END IF
CHECK$ = CK$
END FUNCTION

236. WAP to input string and display the input string in alternate character. E.g computerà cOmPuTeR
CLS
INPUT "ENTER ANY WORD"; S$
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
IF I MOD 2 = 1 THEN
W$ = W$ + LCASE$(B$)
ELSE
W$ = W$ + UCASE$(B$)
END IF
NEXT I
PRINT W$
END SUB


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

SUB ALT$ (S$)
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
IF I MOD 2 = 1 THEN
W$ = W$ + LCASE$(B$)
ELSE
W$ = W$ + UCASE$(B$)
END IF
NEXT I
PRINT W$
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION ALT$ (S$)
CLS
INPUT "ENTER ANY WORD"; S$
PRINT ALT$(S$)
END

FUNCTION ALT$ (S$)
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
IF I MOD 2 = 1 THEN
W$ = W$ + LCASE$(B$)
ELSE
W$ = W$ + UCASE$(B$)
END IF
NEXT I
ALT$ = W$
END FUNCTION

237.  WAP to count the frequency of characters R or S present in the supplied 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 PROCEDURE
DECLARE SUB COUNT (S$)
CLS
INPUT "ENTER ANY STRING"; S$
CALL COUNT(S$)
END

SUB COUNT (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

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

FUNCTION COUNT (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
COUNT = SC

END FUNCTION


238.  WAP to check whether the supplied character is alphabet or not.

CLS
INPUT "ENTER ANY CHARACTER"; A$
B = ASC(A$)
IF B >= 65 AND B <= 90 OR B >= 97 AND B <= 122 THEN
CK$ = "SUPPLIED CHARACTER IS ALPHABET"
ELSE
CK$ = "SUPPLIED CHARACTER IS NOT ALPHABET"
END IF
PRINT CK$
END SUB


USING SUB PROCEDURE
DECLARE SUB CHECK (A$)
CLS
INPUT "ENTER ANY CHARACTER"; A$
CALL CHECK(A$)
END

SUB CHECK (A$)
B = ASC(A$)
IF B >= 65 AND B <= 90 OR B >= 97 AND B <= 122 THEN
CK$ = "SUPPLIED CHARACTER IS ALPHABET"
ELSE
CK$ = "SUPPLIED CHARACTER IS NOT ALPHABET"
END IF
PRINT CK$
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (A$)
CLS
INPUT "ENTER ANY CHARACTER"; A$
PRINT CHECK$(A$)
END

FUNCTION CHECK$ (A$)
B = ASC(A$)
IF B >= 65 AND B <= 90 OR B >= 97 AND B <= 122 THEN
CK$ = "SUPPLIED CHARACTER IS ALPHABET"
ELSE
CK$ = "SUPPLIED CHARACTER IS NOT ALPHABET"
END IF
CHECK$ = CK$
END FUNCTION

Comments

Unknown said…
Program for finding whether the input string is a number , uppercase or lowercase is mistake

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS

PALINDROME AND ARMSTRONG PROGRAMS