Pascal program To Calculate Area of a Triangle

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;
x, y, z , r, area : real;
Function N (I, j, k: real): real;
N:=a + b + c / 2;
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);

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.

Share on Google Plus

About Grace Joseph

Grace Joseph is a tech blogger from Cross River State, Nigeria. She studied Computer Science in University of Calabar and is a lover of tech, music and the Internet. You can follow her on Facebook and Google+


Post a Comment