Write a simple QBASIC program to display the square of 7 using a subroutine

 Here is a simple QBASIC Program on how to display the square of 7 using a subroutine function.

SOLUTION:

SUB DisplaySquare(n)

    DIM square AS INTEGER

    square = n * n

    PRINT "The square of "; n; " is "; square

END SUB

CALL DisplaySquare(7)


OUTPUT:

The square of 7 is 49


EXPLANATION:

SUB DisplaySquare(n): defines a subroutine named DisplaySquare that takes one parameter n


DIM square AS INTEGER: It declares a variable square to store the result of the multiplication.


square = n * n: This line calculates the square of n and stores it in the square variable.


CALL DisplaySquare(7): This line calls the DisplaySquare subroutine with the argument 7. 


And this is how you can use subroutine to display the square of 7.

Post a Comment

Previous Post Next Post