QBASIC – Perimeter of rectangle

Below is the QBASIC program to calculate the perimeter of a rectangle.

REM Program to find perimeter of rectangle
CLS
INPUT "Enter the length: "; l
INPUT "Enter the breadth: "; b
perimeter = 2 * (l + b)
PRINT "Perimeter of the rectangle is: ";perimeter
END

Explanation:

Let’s first see the formula: Perimeter = 2 * (l + b). So, we can determine the perimeter of a rectangle by taking the length and breadth of the rectangle from the user and multiplying the sum of length and breadth by 2.

Similarly, for the perimeter of a square, the formula is Perimeter = 4L. So, we can only ask for length from the user and use the formula.

Leave a Comment

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