#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("Input the x-coordinate of the first point: ");
    scanf("%f", &ax);

    printf("Input the y-coordinate of the first point: ");
    scanf("%f", &ay);

    printf("Input the x-coordinate of the second point: ");
    scanf("%f", &bx);

    printf("Input the y-coordinate of the second point: ");
    scanf("%f", &by);

    printf("Input the x-coordinate of the third point: ");
    scanf("%f", &cx);

    printf("Input the y-coordinate of the third point: ");
    scanf("%f", &cy);

    Calculate_Area_Perimeter_Triangle(ax, ay, bx, by, cx, cy, &perimeter, &area);


    printf("\nArea Using Herons Formula is:  %.4f", area);

    printf("\n");
}
