• Language

    Pascal

  • Description

    Write a program that prompts the user to enter the tree points (x1, y1), (x2, y2), and (x3, y3) of a triangle and displays its area.
    The formula for computing the area of a triangle is:
    s = (side1 + side2 + side3) / 2
    area = sqrt(s * (s - side1) * (s - side2) * (s - side3))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
program AreaOfATriangle;
uses crt, math;

var area, s, side1, side2, side3 : real;
var x1, x2, x3, y1, y2 : real;
var y3 : real;
begin
    write ('Enter the value of x1: ');
    readln (x1);
    write ('Enter the value of x2: ');
    readln (x2);
    write ('Enter the value of x3: ');
    readln (x3);
    write ('Enter the value of y1: ');
    readln (y1);
    write ('Enter the value of y2: ');
    readln (y2);
    write ('Enter the value of y3: ');
    readln (y3);
    side1 := sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    side2 := sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
    side3 := sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
    s := (side1+side2+side3)/2;
    area := sqrt(s*(s-side1)*(s-side2)*(s-side3));
    writeln ('Value of area: ', area:0:6);
    writeln ('Value of s: ', s:0:6);
    writeln ('Value of side1: ', side1:0:6);
    writeln ('Value of side2: ', side2:0:6);
    writeln ('Value of side3: ', side3:0:6);
    writeln;
    write ('Press any key to finish . . . ');
    readkey;
end.