Monday, October 11, 2021

Program to print square root & cube root of an input number (QBASIC)

1. Program to print Square Root of Given Number.

CLS
INPUT "Enter any Number : "; n
sr = n ^ (1 / 2)
PRINT "Square Root = "; sr
END


Using SUB Procedure

DECLARE SUB sqrRoot(n)
CLS
INPUT "Enter any Number : "; n
CALL sqrRoot(n)
END

SUB sqrRoot (n)
     sr = n ^ (1 / 2)
     PRINT "Square Root = "; sr
END SUB


Using FUNCTION Procedure

DECLARE FUNCTION sqrRoot(n) CLS
INPUT "Enter any Number : "; n
sr = sqrRoot(n)
PRINT "Square Root = "; sr
END

FUNCTION sqrRoot (n)
     r = n ^ (1 / 2)
     sqrRoot = r
END FUNCTION


2. Program to print Cube Root of Given Number.

CLS
INPUT "Enter any Number : "; n
cr = n ^ (1 / 3)
PRINT "Cube Root = "; cr
END


Using SUB Procedure

DECLARE SUB cubeRoot(n)
CLS
INPUT "Enter any Number : "; n
CALL cubeRoot(n)
END

SUB cubeRoot (n)
     cr = n ^ (1 / 3)
     PRINT "Cube Root = "; cr
END SUB


Using FUNCTION Procedure

DECLARE FUNCTION cubeRoot(n)
CLS
INPUT "Enter any Number : "; n
cr = cubeRoot(n)
PRINT "Cube Root = "; cr
END

FUNCTION cubeRoot (n)
     r = n ^ (1 / 3)
     cubeRoot = r
END FUNCTION

No comments:

Post a Comment

If you have any doubts, Please let me know.

[Download PDF] Computer Science Book Gread-10 in Nepali Language

 If you are searching for class 10 Computer Science in Nepali pdf for free download then you are at the right page. This book is soley publi...