Wednesday, October 16, 2019

QBASIC to display 1, 2, 3, 5, 8.. 13the 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 capital 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 diaply 50, 42, 35, 29, 24.. 10th 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 word 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

QBASIC to find Prime or Composite using SUB

DECLARE SUB PRIME (N)
INPUT "Enter any number"; N
CALL PRIME (N)
END



SUB PRIME (N)
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN
PRINT N; "IS PRIME NUMBER"
ELSE
PRINT N; "IS COMPOSITE NUMBER"
END IF
END SUB

QBASIC to find factorial using FUNCTION

DECLARE FUNCTION Factorial ( N )
CLS
INPUT "Enter any number"; N

PRINT "Factorial ="; Factorial ( N )
END

FUNCTION Factorail ( N )
F = 1
F = F * I
NEXT I
Factorail = F
END FUNCTION

QBASIC to find Positive or Negative using SUB

DECLARE SUB CHECK(N)
CLS
INPUT"ENTER ANY NO.";N
CALL CHECK (N$)
END



SUB CHECK(N)
IF N > 0 THEN
PRINT "POSITIVE NO."
ELSEIF N  < 0 THEN
PRINT "NEGATIVE NO."
ELSE
PRINT "ZERO"
END IF
END SUB

QBASIC to dispaly 9, 7, 5,...1 using SUB

DECLARE SUB SERIES ( )
CLS
CALL SERIES
END

SUB SERIES ( )
FOR I = 9 TO 1 STEP -2
PRINT I
NEXT I
END SUB

QBASIC to calculate distance travelled using FUNCTION

DECLARE FUNCTION DISTANCE ( U, A, T )
CLS
INPUT "Enter initial velocity"; U
INPUT "Enter acceleration"; A
INPUT "Enter time"; T
PRINT " Distance travelled="; DISTANCE ( U, A, T )
END

FUNCTION DISTANCE ( U, A, T )
DISTANCE = U 8 T + 1 / 2 * A * T ^ 2
END FUNCTION

QBASIC to print only vowel from given word using SUB

DECLARE SUB DISPLAY ( N$ )
INPUT " Enter any number"; N$
CALL DISPLAY ( N$ )
END

SUB DISPLAY ( N$ )
FOR I = 1 TO LEN ( N$ )
B$ = MID $ ( N$, I, 1 )

C$ = UCASE $ ( B$ )
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN D$ = D$ + B$
NEXT I
PRINT "Vowel="; D$
END SUB

QBASIC to find Volume of Box using FUNCTION

DECLARE FUNCTION VOL ( L, B, H )
CLS
INPUT "Enter length"; L
INPUT "Enter breadth"; B
INPUT "Enter height"; H
PRINT "Volume of box"; VOL ( L, B, H )
END

FUNCTION VOL ( L, B, H )
VOL = L * B * H
END FUNCTION

QBASIC to check whether the number is divisible by 13 or not using SUB

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

SUB CHECK ( N )
IF N MOD 13 = 0 THEN
PRINT "The number is divisible by 13"
ELSE
PRINT "The number is not divisible by 13"
END IF
END

QBASIC to find Circumference of Circle using SUB

DECLARE SUB CIR ( R )
CLS
INPUT "Enter radius"; R
CALL CIR ( R )
END

SUB CIR ( R )
C =  2 * 22 / 7 * R
PRINT "Circumference of circle = "; C
END SUB

QBASIC to find Area of 4 walls using FUNCTION

DECLARE FUNCTION Area ( L, B, H )
CLS
INPUT "Enter length"; L
INPUT "Enter breadth"; B
INPUT "Enter height"; H
PRINT "Area of 4 walls = "; Area ( L, B, H )
END

FUNCTION Area ( L, B, H )
Area = 2 * H * ( L + B )
END FUNCTION

QBASIC to find Area of Box using FUNCTION

DECLARE FUNCTION Area ( L, B, H )
CLS
INPUT "Enter length"; L
INPUT "Enter breadtha"; B
INPUT "Enter height"; H
PRINT " Area of box"; Area ( L, B, H )
END

FUNCTION Area ( L, B, H )
Area = 2 * ( L * H + B * H + L * B )
END FUNCTION

QBASIC to display Greatest among 3 numbers using SUB

DECLARE SUB GREAT ( A, B, C )
CLS
INPUT "Enter any three numbers"; A, B, C
CALL GREAT ( A, B, C )
END

SUB GREAT ( A, B, C )
IF A > B AND A > C THEN 
PRINT " The greatest number is A"
ELSEIF B > A AND B > C THEN
PRINT "the greatest number is B"
ELSE
PRINT "The greatest number is C"
END IF 
END SUB

QBASIC to display 1, 1, 2, 3, 5, 8.. upto 10th term using SUB

DECLARE SUB SERIES ( )
CLS
CALL SERIES
END

SUB SERIES ( )
A = 1
B = 1
FOR I = 1 TO 5
PRINT AA
PRINT B
A = A +B
B = A + B
NEXT I
END SUB

QBASIC to print Natural no. from 1 to 5 using SUB

DECLARE SUB SERIES ( )
CLS
CALL SERIES
END

SUB SERIES ( )
FOR I = 1 TO 5
PRINT I
NEXT I
END SUB

QBASIC to print Simple Interest using FUNCTION

DECLARE FUNCTION SI ( P, T, R )
CLS
INPUT "Enter principle"; P
INPUT "Enter time"; T
INPUT "Enter rate"; R
PRINT "Simple Interest = "; SI ( P, T, R )
END

FUNCTION SI ( P, T, R )
SI = ( P* T* R ) / 100
END FUNCTION

QBASIC to conver Temperature in Celsius in Fahrenheit using FUNCTION

DECLARE FUNCTION CEL ( C )
CLS
INPUT "Enter celsius"; C
PRINT "Temperature in celsius fahrenheit = "; CEL ( C )
END

FUNCTION CEL ( C )
CEL = 9 * C / 5 + 32
END FUNCTION

QBASIC to find Sum of digits using SUB

DECLARE SUB SUM ( N )
CLS

INPUT "Enter any number"; N
CALL SUM ( N )
END

SUB SUM ( N )
S = 0
WHILE N <> 0
R = N MOD 10
S = S + R
N = N \ 10
WEND
PRINT "Sum of digits="; S
END SUM

QBASIC to count total no. of constant using FUNCTION

DECLARE FUNCTION COUNT ( N$ )
CLS
INPUT "Enter any word"; N$
PRINT "Total no. of constant = "; COUNT ( N$ )
END

FUNCTION COUNT ( N$ )
C = 0
FOR I = 1 TO LEN ( N$ )
B$ = MID $ ( N$, I, 1 )
C$ = UCASE $ ( B$ )
IF C$ <> "I" AND C$ <> "O" AND C$ "U" THEN C = C + 1
NEXT I
COUNT = C
END FUNCTION

QBASIC to print first ten odd numbers using SUB

DECLARE SUB SERIES ( )
CLS
CALL SERIES
END

SUB SERIES ( )
FOR I = 0 TO 10 STEP 2 
PRINT I
NEXT I
END SUB

QBASIC to find Volume of Cylinder usinf FUNCTION

 DECLARE FUNCTION VOL ( R, H )
CLS
INPUT "Enter radius"; R
INPUT "Enter height"; H
PRINT "Volume of cylinder"; VOL ( R, H )
END

FUNCTION VOL ( R, H )
VOL = 22 / 7 * r ^ 2 * H
END FUNCTION

QBASIC to find Area of Triangle using FUNCTION

DECLARE FUNCTION Area ( B, H)
CLS
INPUT "Enter base"; B
INPUT "Enter height"; H
PRINT "Area of triangle"; Area ( B, H )
END

FUNCTION Area ( B, H )
Area = 1 / 2 * B * H
END FUNCTION

QBASIC to Reverse of Input string using SUB

DECLARE FUNCTION REV $ ( N$ )
CLS
INPUT "Enter name"; N$
PRINT "Reverse string is"; REV$ ( N$ )
END

FUNCTION REV$ ( N$ )
FOR I = LEN ( N$ ) TO 1 STEP -1
B$ = MID $ ( N$, I, 1)
C$ =  C$ + B$
NEXT I
REV$ = C$
END FUNCTION

QBASIC to count number of word in sentence usingt FUNCTION

DECLARE FUNCTION COUNT ( N$ )
CLS
INPUT "Enter any word"; N$
PRINT " Total number of word ="; COUNT ( N$ )
END

FUNCTION COUNT ( N$ )
C = 0
FOR I = 1 TO LEN ( N$)
B$ = MID $ ( N$, I, 1 )
C$ = UCASE $ ( B$ )
C = C + 1
NEXT I
COUNT = C
END FUNCTION

QBASIC to find Area of four walls sing SUB

DECLARE SUB Area ( L, B, H )
CLS
INPUT "Enter length'; L
INPUT "Enter breadth"; B
INPUT "Enter height"; H
CALL Area ( L, B, H)
END

SUB Area ( L, B, H )
A = 2 * H * ( L + B )
PRINT " Area of four walls="; A
END

QBASIC to count total number of vowels in words using FUNCTION

DECLARE FUNCTION COUNT ( N$ ) 
CLS
INPUT "Enter any word"; N$
PRINT "Total number of vowels = "; COUNT ( N$ )
END

FUNCTION COUNT ( N$ )
C = 0
FOR I = 1 TO LEN ( N$ )
B$ = MID $ ( N$, 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
COUNT = C
END FUNCTION

Tuesday, October 15, 2019

QBASIC to find Area of Circle using SUB

DECLARE SUB Area ( R )
CLS
INPUT "Enter radius'; R
CALL Area ( R )
END

SUB Area ( R )
A = 22 / 7 * R ^ 2
PRINT "Area of circle="; A
END SUB

QBASIC to print total number of vowel in given word using SUB

DECLARE SUB COUNT ( N$ )
CLS
INPUT " Enter any word"; N$
CALL COUNT ( N$ )
END

SUB COUNT ( N$ )
C = 0
FOR I = 1 TO LEN ( N$ )
B$ = MID $ ( N$, 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 SUB

QBASIC to find Avearge of three number using FUNCTION

DECLARE FUNCTION AVG ( A, B, C)
CLS
INPUT " Enter any three number"; A, B, C
PRINT " Average of three number"; AVG ( A, B, C)
END

FUNCTION AVG ( A, B, C)
AV = ( A + B + C ) / 3
AVG = AV
END FUNCTION