Saturday, October 22, 2016

Qbasic Program: HCF and LCM



142. WAP TO CHECK WHETHER THE INPUT NUMBER IS PERFECT NUMBER OR NOT.

CLS
INPUT "ENTER ANY NUMBER"; N
S = 0
FOR I = 1 TO N - 1
IF N MOD I = 0 THEN S = S + I
NEXT I
IF S = N THEN
PRINT "PERFECT NUMBER"
ELSE
PRINT "NOT PERFECT NUMBER"
END IF
END

USING SUB PROCEDURE

DECLARE SUB PERFECT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PERFECT (N)
END

SUB PERFECT (N)
S = 0
FOR I = 1 TO N - 1
IF N MOD I = 0 THEN S = S + I
NEXT I
IF S = N THEN
PRINT "PERFECT NUMBER"
ELSE
PRINT "NOT PERFECT NUMBER"
END IF
END SUB





USING FUNCTION PROCEDURE

DECLARE FUNCTION PERFECT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PR = PERFECT (N)
IF PR = N THEN
PRINT "PERFECT NUMBER"
ELSE
PRINT "NOT PERFECT NUMBER"
END IF
END
FUNCTION PERFECT (N)
S = 0
FOR I = 1 TO N - 1
IF N MOD I = 0 THEN S = S + I
NEXT I
PERFECT = S
END FUNCTION

143. WAP TO CHECK WHETHER THE INPUT NUMBER IS PERFECT SQUARE NUMBER OR NOT.

CLS
INPUT "ENTER ANY NUMBER"; N
S = SQR(N)
IF S = INT(S) THEN
PRINT "PERFECT SQUARE"
ELSE
PRINT "NOT PERFECT SQUARE"
END IF
END

USING SUB PROCEDURE

DECLARE SUB PERFECT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL PERFECT (N)
END
SUB PERFECT (N)
S = SQR(N)
IF S = INT(S) THEN
PRINT "PERFECT SQUARE"
ELSE
PRINT "NOT PERFECT SQUARE"
END IF
END SUB

USING FUNCTION PROCEDURE

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



144. WAP TO DISPLAY MULTIPLICATION TABLE OF A GIVEN NUMBER.

CLS
INPUT "ENTER ANY NUMBER"; N
FOR I = 1 TO 10
PRINT N; "X"; I; "="; N * I
NEXT I
END




USING SUB PROCEDURE

DECLARE SUB MUL (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL MUL (N)
END
SUB MUL (N)
FOR I = 1 TO 10
PRINT N; "X"; I; "="; N * I
NEXT I
END SUB

USING FUNCTION  PROCEDURE
DECLARE FUNCTION MUL (N)
CLS
INPUT "ENTER ANY NUMBER"; N
M = MUL(N)
END

FUNCTION MUL (N)
FOR I = 1 TO 10
PRINT N; "X"; I; "="; N * I
NEXT I
END FUNCTION

145. WAP TO DISPLAY H.C.F AND L.C.M OF A GIVEN ANY TWO NUMBERS.
CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
C = A
D = B
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
L = C * D / B
PRINT "H.C.F="; B
PRINT "L.C.M="; L
END
USING SUB PROCEDURE

DECLARE SUB HCFLCM(A, B)
CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
CALL HCFLCM (A, B)
END

SUB HCFLCM (A, B)
C = A
D = B
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
L = C * D / B
PRINT "H.C.F="; B
PRINT "L.C.M="; L
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION HCFLCM(A, B)
CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
PRINT “L.C.M=”; HCFLCM (A, B)
END

FUNCTION HCFLCM (A, B)
C = A
D = B
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
L = C * D / B
PRINT "H.C.F="; B
HCFLCM = L
END FUNCTION
146. WAP TO DISPLAY H.C.F OF A GIVEN ANY TWO NUMBERS.

CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
PRINT "H.C.F="; B
END


USING SUB PROCEDURE


DECLARE SUB HCF(A, B)
CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
CALL HCF (A, B)
END

SUB HCF (A, B)
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
PRINT "H.C.F="; B
END SUB

USING FUNCTION PROCEDURE


DECLARE FUNCTION HCF(A, B)
CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
PRINT “H.C.F=”; HCF (A, B)
END

FUNCTION HCF (A, B)
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
HCF = B
END FUNCTION


147. WAP TO DISPLAY L.C.M OF A GIVEN ANY TWO NUMBERS.
CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
C = A
D = B
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
L = C * D / B
PRINT "L.C.M="; L
END
USING SUB PROCEDURE
DECLARE SUB LCM(A, B)
CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
CALL LCM (A, B)
END
SUB LCM (A, B)
C = A
D = B
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
L = C * D / B
PRINT "L.C.M="; L
END SUB
USING FUNCTION PROCEDURE


DECLARE FUNCTION LCM(A, B)
CLS
INPUT "ENTER ANY TWO NUMBERS"; A, B
PRINT “L.C.M=”; LCM (A, B)
END

FUNCTION LCM (A, B)
C = A
D = B
WHILE A MOD B < > 0
T = A MOD B
A = B
B = T
WEND
L = C * D / B
LCM = L
END FUNCTION

6 comments:

  1. Thanks...it become benefit to us....

    ReplyDelete
  2. can u upload of finding hcf using common shared statement

    ReplyDelete
  3. write a program to find the two largest from a list.for example : from the list, 2,5,6,9,11,17,3. 11 and 17 are the two largest numbers

    1
    SEE ANSWER

    ReplyDelete