PROJECT 'B'

Programming Concept


QBASIC:

1.      Input any string and reverse it.
CLS
INPUT "ENTER ANY STRING"; A$
FOR I = LEN(A$) TO 1 STEP -1
B$ = MID$(A$, I, 1)
C$ = C$ + B$
NEXT I
PRINT "REVERSED STRING IS "; C$
END

2.      Input any string and check whether the given string is palindrome or not.
CLS
INPUT "ENTER ANY STRING"; A$
FOR I = LEN(A$) TO 1 STEP -1
B$ = MID$(A$, I, 1)
C$ = C$ + B$
NEXT I
IF A$ = C$ THEN
PRINT  A$; “IS PALINDROME”
ELSE
PRINT A$; “IS NOT PALINDROME”
END IF
END

3.      Count total no. of vowels in a given string.
CLS
INPUT "ENTER ANY STRING"; A$
VC = 0
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
VC = VC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF VOWELS= "; VC
END

4.      Count total no. of consonants in a given word.
CLS
INPUT "ENTER ANY STRING"; A$
CC = 0
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, 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

5.      Count total no. of vowels and consonants in a given word.
CLS
INPUT "ENTER ANY WORD"; A$
VC = 0
CC = 0
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
VC = VC + 1
ELSE
CC = CC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF VOWELS= "; VC
PRINT "TOTAL NO. OF CONSONANTS="; CC
END

6.      Display vowels from a given string.
CLS
INPUT "ENTER ANY STRING"; A$
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
PRINT B$
END IF
NEXT I
END

7.      Display consonants from a given word.
CLS
INPUT "ENTER ANY STRING"; A$
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
C$ = UCASE$(B$)
IF C$ <> "A" AND C$ <> "E" AND C$ <> "I" AND C$ <> "O"
AND C$ <> "U"  THEN
PRINT B$
END IF
NEXT I
END

8.      Count total no. of words from a given string.
CLS
INPUT "ENTER ANY STRING"; A$
WC = 1
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
IF B$ = " " THEN
WC = WC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF WORDS= "; WC
END 

9.      Count total no. of vowels and consonants from a given string.
CLS
INPUT "ENTER ANY STRING"; A$
VC = 0
CC = 0
WC = 1
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN
VC = VC + 1
ELSEIF B$ = " " THEN
WC = WC + 1
ELSE
CC = CC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF VOWELS= "; VC
PRINT "TOTAL NO. OF CONSONANTS="; CC
END

10.  Input any string and display in alternate case characters. [Example:  Input = COMPUTER ; Output = CoMpUtEr]

CLS
INPUT "ENTER ANY WORD"; A$
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
IF I MOD 2 = 0 THEN
W$ = W$ + UCASE$(B$)
ELSE
W$ = W$ + LCASE$(B$)
END IF
NEXT I
PRINT "Alternate case=";W$
END 

Comments

Popular posts from this blog