Sunday 15 March 2020

QBASIC Program Using Sub Procedure


Write a program to display the sum of individual digits of multi digit input number.

Using Sub Procedure
DECLARE SUB SUMDIG(N)
CLS
INPUT “ENTER MULTIGIT NUMBER” ; N
CALL SUMDIG(N)
END
SUB SUMDIG(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
PRINT “SUM IS ” ; S
END SUB
Using Function Procedure:
DECLARE FUNCTION SDIG(N)
CLS
INPUT”ENTER A NUMBER”; N
PRINT “SUM IS ” ; SDIG(N)
END
FUNCTION SDIG(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
SDIG=S
END FUNCTION
WAP PROGRAM TO DISPLAY AREA OF TRIANGLE
CLS
INPUT “ENTER BREADTH”; B
INPUT “ENTER HEIGHT”; H
A = 1 / 2  * (B * H)
PRINT “AREA OF TRIANGLE “; A
END

USING SUB PROCEDURE
DECLARE SUB AREA (B, H)
CLS
INPUT “ENTER BREADTH”; B
INPUT “ENTER HEIGHT”; H
CALL AREA (B, H)
END

SUB AREA (B, H)
A = 1 / 2  * (B * H)
PRINT “AREA OF TRIANGLE”; A
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION AREA (B, H)
CLS
INPUT “ENTER BREADTH”; B
INPUT “ENTER HEIGHT”; H
AR = AREA( B, H)
PRINT “AREA OF TRIANGLE ”; AR
END

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

Solve a quadratic equation ax2+bx+c=0 on the basis of the coefficient values a, b, and c.
REM SOLVE A QUADRATIC EQUATION
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X; Y
END

USING SUB PROCEDURE
DECLARE SUB EQUATION (A, B, C)
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
CALL EQUATION (A, B, C)
END
SUB EQUATION (A, B, C)
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X; Y
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION EQUATION (A, B, C)
COMMON SHARED X
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X; EQUATION(A, B, C)
END
FUNCTION EQUATION (A, B, C)
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
EQUATION =Y
END FUNCTION

Acceleration of car
Declare sub acc(vi,vf,ti,tf)
CLS
INPUT "enter initial velocity"; vi
INPUT "enter final velocity"; vf
INPUT "enter initial time"; ti
INPUT "enter final time"; tf
CALL acc(vi, vf, ti, tf)
END

SUB acc (vi, vf, ti, tf)
    v = vf - vi
    t = tf - ti
    accl = v / t
    PRINT v
    PRINT t
    PRINT "acceleration is"; accl
END SUB

WAP to input any number and check whether the given no. is positive, negative or zero.
CLS
INPUT “ENTER ANY NUMBER”; N
IF N > 0 THEN
PRINT N; IS POSITIVE NUMBER”
ELSEIF N < 0 THEN
PRINT N; IS NEGATIVE NUMBER”
ELSE
PRINT N; IS ZERO”
END IF
END

USING SUB PROCEDURE
DECLARE SUB CHECK (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CHECK (N)
END
SUB CHECK (N)
IF N > 0 THEN
PRINT N; IS POSITIVE NUMBER”
ELSEIF N < 0 THEN
PRINT N; IS NEGATIVE NUMBER”
ELSE
PRINT N; IS ZERO”
END IF
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT N; “IS “; CHECK$(N)
END

FUNCTION CHECK$ (N)
IF N > 0 THEN
CHECK$ = “POSITIVE NUMBER”
ELSEIF N < 0 THEN
CHECK$ = “NEGATIVE NUMBER”
ELSE
CHECK$ = “ZERO”
END IF
END FUNCTION

WAP to input any number and display whether it is odd or even.
      CLS
      INPUT “ENTER ANY NUMBER”; N
      IF N MOD 2 = 0 THEN
      PRINT N; “IS EVEN NUMBER”
ELSE
PRINT N; “IS ODD NUMBER”
END IF
END

USING SUB PROCEDURE
DECLARE SUB CHECK (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CHECK (N)
END

SUB CHECK (N)
IF N MOD 2 = 0 THEN
      PRINT N; “IS EVEN NUMBER”
ELSE
PRINT N; “IS ODD NUMBER”
END IF
END SUB

USING FUNCTION PROCEDURE
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT “ENTER ANY NUMBER”; N
PRINT N; “IS “; CHECK$(N)
END

FUNCTION CHECK$ (N)
IF N MOD 2 = 0 THEN
CHECK$ = “EVEN NUMBER”
ELSE
CHECK$ = “ODD NUMBER”
END IF
END

Triangle can be formed or not from given 3 sides
Declare sub tri(a,b,c)
CLS
INPUT "first side length"; a
INPUT "second side length"; b
INPUT "third side length"; c
CALL tri(a, b, c)
END

SUB tri (a, b, c)
    IF (a + b > c) THEN
        PRINT "triangle can be formed"
    ELSE
        PRINT "triangle cannot be formed"
    END IF
END SUB

Print first 10 natural number and its square and cube
Declare sub num()
CLS
CALL num
END

SUB num ()
    FOR p = 1 TO 10
        PRINT p
        a = p ^ 2
        PRINT a
        b = p ^ 3
        PRINT b
    NEXT p
END SUB

No comments:

Post a Comment

MCQ Question Bank Microsoft PowerPoint