Programming Concept

QBASIC:




1.      Input any string and reverse it.
CLS
INPUT "Enter any word"; A$
FOR I = LEN(A$) TO 1 STEP -1
B$ = MID$(A$, I, 1)
C$ = C$ + B$
NEXT I
PRINT "Reversed word = "; C$
END

2.      Input any string and check whether the given string is palindrome or not.
CLS
INPUT "Enter  any word"; A$
FOR I = LEN(A$) TO 1 STEP -1
B$ = MID$(A$, I, 1)
C$ = C$ + B$
NEXT I
IF A$ = C$ THEN
PRINT  "The given word is palindrome" 
ELSE
PRINT  "The given word is not a palindrome”
END IF
END

3.      Count total no. of vowels in a given string.
CLS
INPUT "Enter any word"; 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 C = C + 1
NEXT I
PRINT "Total number of vowels= "; C
END

4.      Count total no. of consonants in a given word.
CLS
INPUT "Enter any word"; 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 C = C + 1
NEXT I
PRINT "Total number of  consonants= "; C
END 

5.      Count total no. of vowels and consonants in a given word.
CLS
INPUT "Enter any word"; A$
WC=1
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
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

6.      Display vowels from a given string.
CLS
INPUT "Enter any word"; 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$
NEXT I
END

7.      Display consonants from a given word.
CLS
INPUT "Enter any word"; 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$
NEXT I
END

8.      Count total no. of words from a given string.
CLS
INPUT "Enter any word"; A$
C = 1
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
IF B$ = "  " THEN  C = C + 1
NEXT I
PRINT "Total number of words= "; C
END 

9.      Count total no. of vowels and consonants from a given string.
CLS
INPUT "Enter any word"; 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  number  of  vowels= "; VC
PRINT "Total  number  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
C$ = C$ + LCASE$(B$)
ELSE
C$ = C$ + UCASE$(B$)
END IF
NEXT I
PRINT "Alternate case=";C$
END 


Comments

Popular posts from this blog

PROJECT 'B'