QBASIC program to enter any three numbers and display the middle number
CLS
INPUT
"Enter first number:"; a
INPUT
"Enter second number:"; b
INPUT
"Enter third number:"; c
IF
(a < b AND a > c) OR (a > b AND a < c) THEN
m
= a
ELSEIF
(b < a AND b > c) OR (b > a AND b < c) THEN
m
= b
ELSE
m
= c
END
IF
PRINT
"Middle no:"; m
END
By
using SUB procedure (SUB..END SUB)
DECLARE
SUB middle ()
CLS
CALL
middle
END
SUB
middle
INPUT
"Enter first number:"; a
INPUT
"Enter second number:"; b
INPUT
"Enter third number:"; c
IF
(a < b AND a > c) OR (a > b AND a < c) THEN
m
= a
ELSEIF
(b < a AND b > c) OR (b > a AND b < c) THEN
m
= b
ELSE
m
= c
END
IF
PRINT
"Middle no:"; m
END
SUB
By using FUNCTION procedure ( FUNCTION….END FUNCTION)
DECLARE
FUNCTION middle (a, b, c)
CLS
INPUT
"Enter first number:"; a
INPUT
"Enter second number:"; b
INPUT
"Enter third number:"; c
mi
= middle(a, b, c)
PRINT
"Middle number="; mi
END
FUNCTION
middle (a, b, c)
IF
(a < b AND a > c) OR (a > b AND a < c) THEN
m
= a
ELSEIF
(b < a AND b > c) OR (b > a AND b < c) THEN
m
= b
ELSE
m
= c
END
IF
middle
= m
END
FUNCTION
Output:
No comments:
Post a Comment