Posts

New Questions Answers of SUB...END SUB

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

to define a function that returns difference of the highest number and the lowest number of any ten numbers input by the user in the main module? Reply

DECLARE FUNCTION highest (n()) DECLARE FUNCTION lowest (n()) CLS DIM n(10) FOR i = 1 TO 10 INPUT "enter the numbers"; n(i) NEXT i h = highest(n()) l = lowest(n()) PRINT "the difference between highest and lowest number"; h - l END FUNCTION highest (n()) g = n(1) FOR i = 2 TO 10 IF n(i) > g THEN g = n(i) NEXT i highest = g END FUNCTION FUNCTION lowest (n()) s = n(1) FOR i = 2 TO 10 IF n(i) < s THEN s = n(i) NEXT i lowest = s END FUNCTION

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS

1. 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 2. 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 NUM

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

7. 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 8. 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 INP