1. Write a program to
define a sub procedure Sum (a,b) to display sum of any two numbers input by a
user.
DECLARE SUB Sum(a,b)
CLS
INPUT "ENTER A FIRST
NUMBER";a
INPUT "ENTER A SECOND
NUMBER";b
CALL Sum(a,b)
END
SUB Sum(a,b)
s=a+b
PRINT "SUM=";s
END SUB
2. Write a program to
display area of a rectangle by using SUB...END SUB. This program allows a user
to input required data in the main module.
DECLARE SUB areaRectangle(l,b)
CLS
INPUT "ENTER A LENGTH ";l
INPUT "ENTER A BREADTH";b
CALL areaRectangle(l,b)
END
SUB areaRectangle(l,b)
area=l*b
PRINT "AREA IS ";area
END SUB
3. Enter any two
numbers and display its sum.
REM PROGRAM TO DISPLAY SUM OF TWO
NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = A + B
PRINT “SUM OF TWO NUMBERS”; S
END
USING SUB PROCEDURE
DECLARE SUB SUM (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL SUM(A, B)
END
SUB SUM (A, B)
S = A + B
PRINT “SUM OF TWO NUMBERS”; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SUM (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = SUM(A, B)
PRINT “SUM OF TWO NUMBERS”; S
END
FUNCTION SUM (A, B)
SU = A + B
SUM = SU
END FUNCTION
4. Enter any two
numbers and display its difference.
REM PROGRAM TO DISPLAY DIFFERENCE OF
TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
D = A - B
PRINT “DIFFERENCE OF TWO NUMBERS”; D
END
USING SUB PROCEDURE
DECLARE SUB DIFF (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL DIFF(A, B)
END
SUB DIFF (A, B)
D = A - B
PRINT “DIFFERENCE OF TWO NUMBERS”; D
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION DIFF (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
DI = DIFF(A, B)
PRINT “DIFFERENCE OF TWO NUMBERS”;
DI
END
FUNCTION DIFF (A, B)
D = A - B
DIFF = D
END FUNCTION
5. Enter any two
numbers and display its product.
REM PROGRAM TO DISPLAY PRODUCT OF
TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
P = A * B
PRINT “PRODUCT OF TWO NUMBERS”; P
END
USING SUB PROCEDURE
DECLARE SUB PROD (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL PROD(A, B)
END
SUB PROD (A, B)
P = A * B
PRINT “PRODUCT OF TWO NUMBERS”; P
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION PROD (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
PR = PROD(A, B)
PRINT “PRODUCT OF TWO NUMBERS”; PR
END
FUNCTION PROD (A, B)
P = A * B
PROD = P
END FUNCTION
6. Enter any two
numbers and display its average.
REM PROGRAM TO DISPLAY AVERAGE OF
TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
AV = (A + B) / 2
PRINT “AVERAGE OF TWO NUMBERS”; AV
END
USING SUB PROCEDURE
DECLARE SUB AVERAGE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL AVERAGE(A, B)
END
SUB AVERAGE (A, B)
AV = (A + B) / 2
PRINT “AVERAGE OF TWO NUMBERS”; AV
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION AVERAGE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
AVGR = AVERAGE(A, B)
PRINT “AVERAGE OF TWO NUMBERS”; AVGR
END
FUNCTION AVERAGE (A, B)
AV = (A + B) / 2
AVERAGE = AV
END FUNCTION
7. Enter any two
numbers and display its sum, difference, product and average.
REM PROGRAM TO DISPLAY SUM,
DIFFERENCE, PRODUCT AND AVERAGE OF TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = A + B
D = A – B
P = A * B
AV = (A + B) / 2
PRINT “SUM OF TWO NUMBERS”; S
PRINT “DIFFERENCE OF TWO NUMBERS”; D
PRINT “PRODUCT OF TWO NUMBERS”; P
PRINT “AVERAGE OF TWO NUMBERS”; AV
END
USING SUB PROCEDURE
DECLARE SUB SUM (A, B)
DECLARE SUB DIFF (A, B)
DECLARE SUB PROD (A, B)
DECLARE SUB AVERAGE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL SUM(A, B)
CALL DIFF(A, B)
CALL PROD(A, B)
CALL AVERAGE(A, B)
END
SUB SUM (A, B)
S = A + B
PRINT “SUM OF TWO NUMBERS”; S
END SUB
SUB DIFF (A, B)
D = A - B
PRINT “DIFFERENCE OF TWO NUMBERS”; D
END SUB
SUB PROD (A, B)
P = A * B
PRINT “PRODUCT OF TWO NUMBERS”; P
END SUB
SUB AVERAGE (A, B)
AV = (A + B) / 2
PRINT “AVERAGE OF TWO NUMBERS”; AV
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SUM (A, B)
DECLARE FUNCTION DIFF (A, B)
DECLARE FUNCTION PROD (A, B)
DECLARE FUNCTION AVERAGE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = SUM(A, B)
D = DIFF (A, B)
P = PROD(A, B)
AV = AVERAGE(A, B)
PRINT “SUM OF TWO NUMBERS”; S
PRINT “DIFFERENCE OF TWO NUMBERS”; D
PRINT “PRODUCT OF TWO NUMBERS”; P
PRINT “AVERAGE OF TWO NUMBERS”; AV
FUNCTION SUM (A, B)
SU = A + B
SUM = SU
END FUNCTION
FUNCTION DIFF (A, B)
D = A - B
DIFF = D
END FUNCTION
FUNCTION PROD (A, B)
P = A * B
PROD = P
END FUNCTION
FUNCTION AVERAGE (A, B)
AVGR = (A + B) / 2
AVERAGE = AVGR
END FUNCTION
8. Enter any three
numbers and display its sum, product and average.
REM PROGRAM TO DISPLAY SUM, PRODUCT
AND AVERAGE OF THREE NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
S = A + B + C
P = A * B * C
AV = (A + B + C) / 3
PRINT “SUM OF THREE NUMBERS”; S
PRINT “PRODUCT OF THREE NUMBERS”; P
PRINT “AVERAGE OF THREE NUMBERS”; AV
END
USING SUB PROCEDURE
DECLARE SUB SUM (A, B, C)
DECLARE SUB PROD (A, B, C)
DECLARE SUB AVERAGE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THREE NUMBERS”; C
CALL SUM(A, B, C)
CALL PROD(A, B, C)
CALL AVERAGE(A, B, C)
END
SUB SUM (A, B, C)
S = A + B + C
PRINT “SUM OF THREE NUMBERS”; S
END SUB
SUB PROD (A, B, C)
P = A * B * C
PRINT “PRODUCT OF THREE NUMBERS”; P
END SUB
SUB AVERAGE (A, B)
AV = (A + B + C) / 3
PRINT “AVERAGE OF THREE NUMBERS”; AV
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SUM (A, B, C)
DECLARE FUNCTION PROD (A, B, C)
DECLARE FUNCTION AVERAGE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
S = SUM(A, B, C)
P = PROD(A, B, C)
AV = AVERAGE(A, B, C)
PRINT “SUM OF THREE NUMBERS”; S
PRINT “PRODUCT OF THREE NUMBERS”; P
PRINT “AVERAGE OF THREE NUMBERS”; AV
FUNCTION SUM (A, B, C)
SU = A + B + C
SUM = SU
END FUNCTION
FUNCTION PROD (A, B, C)
P = A * B * C
PROD = P
END FUNCTION
FUNCTION AVERAGE (A, B, C)
AVGR = (A + B + C) / 2
AVERAGE = AVGR
END FUNCTION
9. Display square of
an input number.
REM PROGRAM TO DISPLAY SQUARE OF AN
INPUT NUMBER
CLS
INPUT “ENTER ANY NUMBER”; N
S = N ^ 2
PRINT “SQUARE OF NUMBER ”; S
END
USING SUB PROCEDURE
DECLARE SUB SQUARE (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL SQUARE(N)
END
SUB SQUARE (N)
S = N ^ 2
PRINT “SQUARE OF NUMBER “; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SQUARE (N)
CLS
INPUT “ENTER ANY NUMBER”; N
S = SQUARE(N)
PRINT “SQUARE OF NUMBER “; S
END
FUNCTION SQUARE (N)
SQ= N ^ 2
SQUARE = SQ
END FUNCTION
10. Display cube of an
input number.
REM PROGRAM TO DISPLAY CUBE OF AN
INPUT NUMBER
CLS
INPUT “ENTER ANY NUMBER”; N
C = N ^ 3
PRINT “CUBE OF NUMBER ”; C
END
USING SUB PROCEDURE
DECLARE SUB CUBE (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CUBE(N)
END
SUB CUBE (N)
C = N ^ 3
PRINT “CUBE OF NUMBER “; C
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CUBE (N)
CLS
INPUT “ENTER ANY NUMBER”; N
C = CUBE(N)
PRINT “CUBE OF NUMBER “; C
END
FUNCTION CUBE (N)
CB = N ^ 3
CUBE = CB
END FUNCTION
11. Display square
root of an input number.
REM PROGRAM TO DISPLAY SQUARE ROOT
OF AN INPUT NUMBER
CLS
INPUT “ENTER ANY NUMBER”; N
S = N ^ (1 / 2)
PRINT “SQUARE ROOT OF NUMBER ”; S
END
USING SUB PROCEDURE
DECLARE SUB SQROOT (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL SQROOT(N)
END
SUB SQROOT (N)
S = N ^ (1 / 2)
PRINT “SQUARE ROOT OF NUMBER “; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SQROOT (N)
CLS
INPUT “ENTER ANY NUMBER”; N
S = SQROOT(N)
PRINT “SQUARE ROOT OF NUMBER “; S
END
FUNCTION SQROOT (N)
SQ= N ^ (1 / 2)
SQROOT = SQ
END FUNCTION
12. Display cube root
of an input number.
REM PROGRAM TO DISPLAY CUBE ROOT OF
AN INPUT NUMBER
CLS
INPUT “ENTER ANY NUMBER”; N
C = N ^ (1 / 3)
PRINT “CUBE ROOT OF NUMBER ”; C
END
USING SUB PROCEDURE
DECLARE SUB CBROOT (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CBROOT(N)
END
SUB CBROOT (N)
C = N ^ (1 / 3)
PRINT “CUBE ROOT OF NUMBER “; C
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CBROOT (N)
CLS
INPUT “ENTER ANY NUMBER”; N
C = CBROOT(N)
PRINT “CUBE ROOT OF NUMBER “; C
END
FUNCTION CBROOT (N)
CB= N ^ (1 / 3)
CBROOT = CB
END FUNCTION
13. Display sum of
square of any two input numbers.
REM PROGRAM TO DISPLAY SUM OF SQUARE
OF ANY TWO INPUT NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = A ^ 2 + B ^ 2
PRINT “SUM OF SQUARE OF TWO NUMBERS
”; S
END
USING SUB PROCEDURE
DECLARE SUB SQUARE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL SQUARE(A, B)
END
SUB SQUARE (A, B)
S = A ^ 2 + B ^ 2
PRINT “SUM OF SQUARE OF TWO NUMBERS
“; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SQUARE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = SQUARE(A, B)
PRINT “SUM OF SQUARE OF TWO NUMBERS
“; S
END
FUNCTION SQUARE (N)
SQ= A ^ 2 + B ^ 2
SQUARE = SQ
END FUNCTION
14. Display sum of
cube of any two input numbers.
REM PROGRAM TO DISPLAY SUM OF CUBE
OF ANY TWO INPUT NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
C = A ^ 3 + B ^ 3
PRINT “SUM OF CUBE OF TWO NUMBERS ”;
C
END
USING SUB PROCEDURE
DECLARE SUB CUBE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL CUBE (A, B)
END
SUB CUBE (A, B)
C = A ^ 3 + B ^ 3
PRINT “SUM OF CUBE OF TWO NUMBERS “;
C
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CUBE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
C = CUBE (A, B)
PRINT “SUM OF CUBE OF TWO NUMBERS “;
C
END
FUNCTION CUBE (N)
CB= A ^ 3 + B ^ 3
CUBE = CB
END FUNCTION
15. Display sum of
square of any three input numbers.
REM PROGRAM TO DISPLAY SUM OF SQUARE
OF ANY THREE INPUT NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
S = A ^ 2 + B ^ 2 + C ^ 2
PRINT “SUM OF SQUARE OF THREE
NUMBERS ”; S
END
USING SUB PROCEDURE
DECLARE SUB SQUARE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
CALL SQUARE(A, B, C)
END
SUB SQUARE (A, B, C)
S = A ^ 2 + B ^ 2 + C ^ 2
PRINT “SUM OF SQUARE OF THREE
NUMBERS “; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SQUARE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
S = SQUARE(A, B, C)
PRINT “SUM OF SQUARE OF THREE
NUMBERS “; S
END
FUNCTION SQUARE (N)
SQ= A ^ 2 + B ^ 2 + C ^ 2
SQUARE = SQ
END FUNCTION
16. Display sum of
cube of any three input numbers.
REM PROGRAM TO DISPLAY SUM OF CUBE
OF ANY THREE INPUT NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
S = A ^ 3 + B ^ 3 + C ^ 3
PRINT “SUM OF CUBE OF THREE NUMBERS
”; S
END
USING SUB PROCEDURE
DECLARE SUB CUBE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
CALL CUBE (A, B, C)
END
SUB CUBE (A, B, C)
C = A ^ 3 + B ^ 3 + C ^ 3
PRINT “SUM OF CUBE OF THREE NUMBERS
“; C
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION CUBE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
C = CUBE (A, B, C)
PRINT “SUM OF CUBE OF THREE NUMBERS
“; C
END
FUNCTION CUBE (N)
CB= A ^ 3 + B ^ 3 + C ^ 3
CUBE = CB
END FUNCTION
17. WAP to input
number and check whether the given no. is prime or composite.
CLS
INPUT "ENTER ANY NUMBER";
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
USING SUB PROCEDURE
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
USING FUNCTION PROCEDURE
DECLARE FUNCTION PRIME(N)
CLS
INPUT "ENTER ANY NUMBER";
N
P = PRIME (N)
IF P = 2 THEN
PRINT N; "IS PRIME NUMBER"
ELSE
PRINT N; "IS COMPOSITE
NUMBER"
END IF
END
FUNCTION PRIME (N)
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
PRIME = C
END FUNCTION
18. WAP to
display all prime numbers from 1 to 100.
CLS
FOR N = 1 TO 100
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN PRINT N,
NEXT N
END
USING SUB PROCEDURE
DECLARE SUB PRIME ( )
CLS
CALL PRIME
END
SUB PRIME
FOR N = 1 TO 100
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN PRINT N,
NEXT N
END SUB
19. WAP to
display first 15 prime numbers
CLS
N = 1
CNT = 1
TOP:
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN
PRINT N,
CNT = CNT + 1
END IF
N = N + 1
IF CNT <= 15 THEN GOTO TOP
END
USING SUB PROCEDURE
DECLARE SUB PRIME ( )
CLS
CALL PRIME
END
SUB PRIME
N = 1
CNT = 1
TOP:
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN
PRINT N,
CNT = CNT + 1
END IF
N = N + 1
IF CNT <= 15 THEN GOTO TOP
END SUB
20. WAP to input
number and check whether the given no. is prime or not.
CLS
INPUT "ENTER ANY NUMBER";
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 NOT PRIME
NUMBER"
END IF
END
USING SUB PROCEDURE
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 NOT PRIME
NUMBER"
END IF
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION PRIME(N)
CLS
INPUT "ENTER ANY NUMBER";
N
P = PRIME (N)
IF P = 2 THEN
PRINT N; "IS PRIME NUMBER"
ELSE
PRINT N; "IS NOT PRIME
NUMBER"
END IF
END
FUNCTION PRIME (N)
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
PRIME = C
END FUNCTION
21. WAP to
input number and check whether the given no. composite or not.
CLS
INPUT "ENTER ANY NUMBER";
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 COMPOSITE
NUMBER"
ELSE
PRINT N; "IS NOT COMPOSITE
NUMBER"
END IF
END
USING SUB PROCEDURE
DECLARE SUB COMPOSITE (N)
INPUT "ENTER ANY NUMBER";
N
CALL COMPOSITE (N)
END
SUB COMPOSITE (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 COMPOSITE
NUMBER"
ELSE
PRINT N; "IS NOT COMPOSITE
NUMBER"
END IF
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION COMPOSITE (N)
CLS
INPUT "ENTER ANY NUMBER";
N
CO = COMPOSITE (N)
IF CO < > 2 THEN
PRINT N; "IS COMPOSITE
NUMBER"
ELSE
PRINT N; "IS NOT COMPOSITE
NUMBER"
END IF
END
FUNCTION COMPOSITE (N)
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
COMPOSITE = C
END FUNCTION