Write a pascal program that uses a function subprogram called N to calculate the area of a triangle with the formula: Area=√N(N-X)(N-Y)(N-Z) where N= x + y + z / 2

Program area_Of_triangle;

Var

x, y, z , r, area : real;

Function N (I, j, k: real): real;

Begin

N:=a + b + c / 2;

End;

Begin

Writeln (' enter values for x, y, z');

Readln (x, y, z);

r := N(x, y, z);

Area:= sqrt( r- x)*(r-y)*(r-z);

Writeln ('Area:', area);

Readln

End.

The global variables have been declared at the top which is x, y, z. The function carries the local variables i, j, k which must be of the same type as the global variables (real, integer, string or any other). But __in__ this case, the appropriate type is a real data type.

Using the formula of N in the question, this formula isassigned to N in the program.

Next the values are read in by the user which is prompted by 'enter the values for x, y, z'. These identifiers (x, y, z take the values of I, j,k) replace the local variables when the is function N is called and assigned to 'r'. The later part to the program calculates the area of the triangle.

Do you like this post? Please link back to this article by copying one of the codes below.

URL Of Post:

HTML Link Code:

BB (forum) link code:

## Comments

## Post a Comment

Please share your views on this topic with Grace Joseph by leaving a comment.