QBASIC – Area of a triangle when all three sides are given

Below is the QBASIC program to calculate the area of a triangle when all three sides are given.

REM Program to find area of triangle when all three sides are given
CLS
INPUT "Enter the first side: "; a
INPUT "Enter the second side: "; b
INPUT "Enter the third side: "; c
s = (a + b + c)/2
area = (s*(s-a)*(s-b)*(s-c))^(1/2)
PRINT "Area of the triangle is: ";area
END

Explanation:

First the formula: Area = ((s*(s-a)*(s-b)*(s-c))^(1/2)). Let’s break and understand the formula. The formula has frequent use of s variable. Here, s is the semi-perimeter of the triangle, calculated using formula; s = (a + b + c) / 2. Finally, after the semi-perimeter is calculated, we can use the formula of the area which is the square root (notice ^1/2 at the end) of the product of semi-perimeter (s) and the difference of semi-perimeter and each side of the triangle [s*(s-a)*(s-b)*(s-c)].

Leave a Comment

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

Exit mobile version