QBASIC – Calculate the sum of squares

The program below calculates the sum of squares of two user input numbers.

' Program to find sum of squares of two user input numbers
CLS
INPUT "Enter the first number: "; a
INPUT "Enter the second number: "; b
sum = a ^ 2 + b ^ 2
PRINT "Sum of squares of ";a;" and ";b;" is: ";sum
END

Explanation:

To calculate the sum of squares of two user input numbers. We are using the exponentiation operator (^) to calculate the squares of the numbers i.e., a ^ 2 and b ^ 2 to calculate the squares of a and b respectively.

Leave a Comment

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