QBASIC – Calculate square root and cube root of a number

Following is a program to calculate the square root and cube root of any user-entered number in QBASIC.

' Program to find square root and cube root of a number
CLS
INPUT "Enter a number"; a
squareroot = a ^ (1/2)
cuberoot = a ^ (1/3)
PRINT "The square root of the number is ";squareroot
PRINT "The cube root of the number is ";cuberoot
END

Explanation:

To calculate the square root or cube root of any number, we will be using the exponentiation operator (^) as used in calculating the square and cube of any number. However, unlike raising the power of 2 to calculate square and 3 to calculate cube, we need to raise the power of (1/2) and (1/3) to calculate square root and cube root respectively.

Leave a Comment

Your email address will not be published. Required fields are marked *