Concept of a Triangle: In geometry, a two-dimensional flat shape with three non-collinear points and three line segments connecting the vertices forms a triangle. A simple, convex polygon with three sides is called a triangle.
Calculating the Perimeter of a Triangle Using Pascal
Pascal Exercise: Calculate Triangle Perimeter
In this article, Mytour will guide you on how to write a Pascal program to calculate the perimeter of a triangle.
Step 1: Open your Pascal program to declare basic information like:
program Calculate_Triangle_Perimeter;
Declare variables
Step 2: Next, declare data types (var) as follows:
var a, b, c, d: integer
Where:
- a represents the length of side a
- b represents the length of side b
- c represents the length of side c
- d is the perimeter of the triangle.
Step 3: Declare d=a+b+c for the perimeter calculation.
After that, print the result on the screen using the following code:
Writeln('Perimeter of the triangle is',d);
Readln;
End the program.
Step 4: Run the program by pressing Alt + F9
If there are declaration errors, you will receive a notification as shown below:
Modify as shown in the image below (the image adds a semicolon before readln(a), readln(b), readln(c))
If there are no errors, the interface will display a notification as shown in the image below:
Press any key to display the black Pascal interface -> here, enter the 3 sides of the triangle in order -> the application will immediately show the perimeter of the triangle.
Above is the sharing of solving Pascal exercises calculating the perimeter of a triangle using the basic Pascal programming language. To solve exercises on the Pascal application effectively, a solid understanding of foundational knowledge is crucial. In this article, you need to understand what the perimeter of a triangle is, how to calculate it, and then apply the known concepts to write it in the Pascal programming language on the Pascal application. Wish you success!
