Saturday, October 22, 2016

Qbasic Program: Square root



10. 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









11. 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









12. 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









13. 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









14. 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






15. 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






16. 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


17. 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

1 comment: