QBASIC – Find the cube of a number

Below is the program to calculate the cube of the user input number.

' Program to input a number and display its cube
CLS
  INPUT "Enter a number";a
  cube = a ^ 3
  PRINT "The square of the number is ";cube
END

Explanation:

To find the cube, we will be using the exponentiation operator (^). The operator is used to raise a number to an exponent of a designated number. Coming to the example, a ^ 3 is used which means a is raised to the power of 3 giving back the cube of a (user input number).

Similarly, to calculate the cube, cube= a * a * a can be used instead of cube = a ^ 3.

Leave a Comment

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