Example 42: Area and Perimeter of a Triangle

Learn how to calculate the area and perimeter of a triangle using pointers.

Problem

Write a function that calculates the area and perimeter of the triangle. It receives three sides of a triangle along with two pointers to store the results as parameters.

If the lengths of the sides of a triangle are denoted by a, b, and c, then the area of a triangle is given by:

area=S(Sa)(Sb)(Sc)area = \sqrt{S(S - a)(S - b)(S - c)}

where,

S=(a+b+c)2S = \frac{( a + b + c )}{2}

Example

Input (a,b,c) Output (Area, Parameter)
3, 4, 5 6.000000, 12.000000
3.5, 5.5, 6.5 9.624797, 15.500000

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Get hands-on with 1400+ tech skills courses.