# Turbo C - Find Area and Perimeter of a Triangle Given 3 points

Here is the Turbo C source code to find Area or Perimeter of a Triangle given 3 points

Heron's formula for area calculation is given below:

perimeter = A + B + C

float s = perimeter / 2;

area = sqrt( s * (s-A) * (s-B) * (s-C))

Where,

A = Distance between point A and B
B = Distance between point B and C
C = Distance between point C and A

## Source Code

#include <stdio.h>

#include <math.h>

int Calculate_Area_Perimeter_Triangle(float ax, float ay, float bx, float by, float cx, float cy, float *perimeter, float *area)

{

float A = sqrt((double)(bx-ax) * (bx-ax) + (by-ay) * (by-ay));

float B = sqrt((double)(bx-cx) * (bx-cx) + (by-cy) * (by-cy));

float C = sqrt((double)(ax-cx) * (ax-cx) + (ay-cy) * (ay-cy));

float height = 0;

// Heron's formula for area calculation

// area = sqrt( s * (s-a) * (s-b) * (s-c))

float s = (A + B + C) / 2;

*perimeter = A + B + C;

*area = sqrt( s * (s-A) * (s-B) * (s-C));

// area = 1/2 * base * height

// if side A is base, then height

height = (*area * 2) / A;

return 1;

}

void main()

{

float m1, c1, m2, c2;

float ax, ay, bx, by, cx, cy;

float perimeter, area;

float angleA, angleB, angleC;

int type = 0;

float total = 0;

printf("Program to find the Area and Perimeter of a triangle:\n");

printf("Enter Triangle Point A - X: ");

scanf("%f", &ax);

printf("Enter Triangle Point A - Y: ");

scanf("%f", &ay);

printf("Enter Triangle Point B - X: ");

scanf("%f", &bx);

printf("Enter Triangle Point B - Y: ");

scanf("%f", &by);

printf("Enter Triangle Point C - X: ");

scanf("%f", &cx);

printf("Enter Triangle Point C - Y: ");

scanf("%f", &cy);

Calculate_Area_Perimeter_Triangle(ax, ay, bx, by, cx, cy, &perimeter, &area);

printf("\nPerimeter: %.4f", perimeter);

printf("\nArea:  %.4f", area);

printf("\n");

}

## Output

Program to find the given type of the triangle:

Enter Triangle Point A - X: 10

Enter Triangle Point A - Y: 10

Enter Triangle Point B - X: 20

Enter Triangle Point B - Y: 10

Enter Triangle Point C - X: 15

Enter Triangle Point C - Y: 15

Perimeter: 24.1421

Area:  25.0000

Press any key to continue . . .