Wednesday, 30 October 2019

Qbasic to display 1, 2, 3, 5, 8.. 13th term using Sub

DECLARE SUB SERIES ( )

CLS
CALL SERIES
END

SUB SERIES
A = 1
B = 2
FOR I = 1 TO 13
PRINT A;
C = A+B
A = B
B = C
NEXT I
END SUB

Qbasic to find perfect square or not using Function

DECLARE FUNCTION PERFECT (S)
CLS
INPUT "Enter any number"; N
S = SQR(N)
PR = PERFECT (S)
IF PR = S THEN
PRINT "PERFECT SQUARE"
ELSE
PRINT "NOT PERFECT SQUARE"
END IF
END

 
FUNCTION PERFECT (S)
PERFECT = INT (S)
END FUNCTION

Qbasic to find positive, negative or neutral using Sub

DECLARE SUB CHECK(N)
CLS
INPUT "Enter any number.";N
CALL CHECK(N)
END

SUB CHECK(N)
IF N > 0  THEN
PRINT "The number is positive"
ELSEIF N < 0 THEN
PRINT"The number is negative"
ELSE
PRINT "The number is neutral"
END IF
END SUB

Qbasic to erase vowel from input string using Function

DECLARE FUNCTION ERA (A$)
CLS
INPUT "Enter any string";A$
PRINT "String without vowels =";ERA(A$)
END

FUNCTION ERA(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 D$ = D$ + C$
END IF
NEXT I
ERA = D$
END FUNCTION

Qbasic to check input character is capita or small using Function

DECLARE FUNCTION CHECK$(A$)

CLS
INPUT "Enter any character";A$
PRINT "The entered character is"; CHECK$(C$)
END

FUNCTION CHECK$(A$)
C = ASC(A$)
IF C > = 65 AND C < = 91 THEN
CHECK$="UPPER CASE"
ELSEIF C > = 97 AND C < = 122 THEN
CHECK$ ="LOWER CASE"
ELSE 
CHTR$="NOT A CHARACTER"
END IF
END FUNCTION

Qbasic to display 50, 42, 35, 29, 24 10 th term using Sub

DECLARER SUB SERIES( )

CLS
CALL SERIES
END

SUB SERIES( )
A = 50
B = 8
FOR I = 1 TO 10
PRINT A
A = A - B
B = B - 1
NEXT I
END

Qbasic to find palindrome using Function

DECLARE FUNCTION PAL$ ( N$ )
CLS
INPUT "Enter any number"; N$
P$ = PAL$ ( N$ )
IF N$ = P$ THEN
PRINT  "The given word is Palindrome'
ELSE
PRINT " The given word is not Palindrome"
END IF
END

FUNCTION PAL$ (N$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$( N$, I, 1)
L$ = L$ + B$
NEXT I
PAL$ = L$
END FUNCTION