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

From the above question, this is a Pascal program to calculate the Area of a triangle, but not using the basic formula A = 1/2 base x height.

If you're good in Mathematics, then more than half your programming problems will be solved as every good mathematician is considered a programmer with great potentials.

In this case,

We have been given the formula to work with and our programming code must follow.

Here's a sample of how your code should look like.

### Program Code

Program area_Of_triangle;

Var

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

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

Var

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

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

Begin

N:=x + y + z / 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.

### Logic of The Program

- The global variables have been declared at the top, which are x, y, z, r, and area.

- The Function N defines the variables i, j, k which must be of the same data type (real, integer, string or any other) as the global variables to avoid errors, which in this case, the appropriate type is the real data type.

- Using the formula of N ( N= x + y + z / 2) in the question, the same formula is assigned to N in the program as N:=x + y + z / 2;.

- Next, the user is prompted to enter three numbers which are read in as values for x, y, z.

- These identifiers (x, y, z take the values of I, j, k) and replace the local variables when the Function N is called and assigned to 'r'.

- The latter part of the program calculates the area of the triangle.

#### Conclusion

Now there are various ways you can write the same program since everyone thinks differently.

That being so, you can try rewriting the above code to show your understanding of the Pascal code example.

If you have questions, then leave a comment in the section below and we'll respond as we can.

Also Read:

**BASIC Program For Sum of Numbers Using IF Then Statement**

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.