Library Functions of QBasic Examples

library functions of qbasic examples
Library Functions (Click Here)
Convert Decimal to Binary  

CLS

INPUT "ENTER DECIMAL NUMBER" ; D

WHILE D < > 0

R = D MOD 2

S$ = STR$(R) + S$

D = D \ 2

WEND

PRINT "BINARY EQUIVALENT VALUE"; S$

END


Convert Binary to Decimal

CLS

INPUT "ENTER BINARY NUMBER"; N$

FOR I = LEN(N$) TO 1 STEP -1

B$ = MID$(N$, I, 1)

S = S + VAL(B$) * 2 ^ P

P = P + 1

NEXT I

PRINT "DECIMAL EQUIVALENT VALUE="; S

END





Convert Decimal to Hexadecimal

CLS

INPUT "ENTER DECIMAL NUMBER"; D

WHILE D <> 0

R = D MOD 16

IF R < 10 THEN

S$ = STR$(R) + S$

ELSE

S$ = CHR$(R + 55) + S$

END IF

D = D \ 16

WEND

PRINT "HEXADECIMAL EQUIVALENT VALUE="; S$

END


Convert Hexadecimal to decimal

CLS

INPUT "ENTER HEXADECIMAL NUMBER"; N$

FOR I = LEN(N$) TO 1 STEP -1

B$ = MID$(N$, I, 1)

IF B$ = "A" THEN B$ = "10"

IF B$ = "B" THEN B$ = "11"

IF B$ = "C" THEN B$ = "12"

IF B$ = "D" THEN B$ = "13"

IF B$ = "E" THEN B$ = "14"

IF B$ = "F" THEN B$ = "15"

S = S + VAL(B$) * 16 ^ P

P = P + 1

NEXT I

PRINT "DECIMAL EQUIVALENT VALUE="; S

END




 

Input any string and count total no of vowel

CLS

INPUT "ENTER ANY STRING"; 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

END IF

NEXT I

PRINT "TOTAL NO. OF VOWELS= "; VC

END

Insert String, Remove Vowel and Print

CLS
INPUT "Enter the string"; s$
b$ = UCASE$(s$)
FOR i = 1 TO LEN(b$)
c$ = MID$(b$, i, 1)
IF c$ <> "A" AND c$ <> "E"AND c$ <> "I" AND c$ <> "O" AND c$ <> "U" THEN
n$ = n$ + c$
END IF
NEXT i
PRINT "The word without the vowels is"; n$
END

 

Given word is Palindrome or Not

CLS
INPUT "Enter any Word"; A$
FOR i = LEN(A$) TO 1 STEP -1
B$ = B$ + MID$(A$, i, 1)
NEXT i
IF B$ = A$ THEN
PRINT "It is palindrome"
ELSE
PRINT "it is not palindrome"
END IF
END

 

Given Number is perfect Square or Not

CLS
INPUT "enter any number"; n
A = SQR(n)
IF A = INT(A) THEN
PRINT "perfect square"
ELSE
PRINT "Not perfect square"
END IF
END




 

Digital Clock

CLS
PRINT "***************************************************************************************************"
LOCATE 2, 30: PRINT "Digital Clock"
PRINT "***************************************************************************************************"
FOR i = 1 TO 10
LOCATE 11, i + 32: PRINT "-"
LOCATE 13, i + 32: PRINT "-"
NEXT i
LOCATE 12, 33: PRINT "~"
LOCATE 12, 42: PRINT "~"
a$ = TIME$
DO
LOCATE 12, 34: PRINT a$
a$ = TIME$
LOOP WHILE INKEY$ = ""
PRINT "***************************************************************************************************"
LOCATE 2, 30: PRINT “Digital Clock”
PRINT "***************************************************************************************************"

END

 

Armstrong or Not Armstrong

CLS
INPUT "enter any number"; num
n = num

WHILE num <> 0
r = num MOD 10
num = num \ 10
sum = sum + (r ^ 3)
WEND
IF n = sum THEN
PRINT "armstrong"
ELSE
PRINT "not arm strong"
END IF
END

 

Input numbers and find sum

CLS
INPUT "enter any number"; n
WHILE n <> 0
r = n MOD 10
s = s + r
n = INT(n / 10)
WEND
PRINT "sum of digits"; s
END

Alternate characters in capital letters. (eg: PrOgRaMmInG)

CLS
INPUT "enter a string"; s$
FOR i = 1 TO LEN(s$)
c$ = MID$(s$, i, 1)
IF i MOD 2 = 1 THEN
w$ = w$ + UCASE$(c$)
ELSE
w$ = w$ + LCASE$(c$)
END IF
NEXT i
PRINT w$
END

 

Count Repeated Letter

CLS
INPUT "enter a string"; s$

FOR i = 1 TO LEN(s$)
c$ = MID$(s$, i, 1)
IF c$ =  "a" THEN c = c + 1
NEXT i
PRINT "repeated (a)”"; c
END

 

Find  "A" and Replace Letter with "@"

CLS
INPUT "Enter a word: ", s$
FOR i = 1 TO LEN(s$)
b$ = UCASE$(s$)
c$ = MID$(b$, i, 1)
IF c$ = "A" THEN c$ = "@"
n$ = n$ + c$
NEXT i
PRINT "Word after change is:"; n$
END

 

Count Words

CLS
INPUT "ENTER ANY STRING"; S$
WC = 1
FOR I = 1 TO LEN(S$)
B$ = MID$(S$, I, 1)
IF B$ = "" THEN
WC = WC + 1
END IF
NEXT I
PRINT "TOTAL NO. OF WORDS= "; WC
END

STRING  PATTERNS (CLICK HERE)
NUMERIC  PATTERNS (CLICK HERE)

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image