//* Three purposes of using functions *

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> double Distance_Between_Points(double point1x, double point1y, double point2x, double point2y); double Area_of_Triangle(double leg_lenght_a, double leg_lenght_b, double leg_lenght_c); int main() { double point1x, point1y, point2x, point2y, point3x, point3y; double d1, d2, d3, area; printf("Please enter the coordinates of the triangle vertices and press ENTER.\n"); scanf("%lf %lf %lf %lf %lf %lf", &point1x, &point1y, &point2x, &point2y, &point3x, &point3y); d1=Distance_Between_Points(point1x, point1y, point2x, point2y); d2=Distance_Between_Points(point3x, point3y, point2x, point2y); d3=Distance_Between_Points(point1x, point1y, point3x, point3y); area=Area_of_Triangle(d1, d2, d3); printf("The area of the triangle is %.2lf\n", area); return(0); } /* inline */ double sqr (double x) { // return(pow(fabs(x),2)); return(x*x); } double Distance_Between_Points(double x1, double y1, double x2, double y2) { return( sqrt( sqr(x2-x1) + sqr(y2-y1) ) ); // OR // return( sqrt( pow( fabs(x2-x1),2)+pow( fabs(y2-y1),2) ) ); // warning: C library requires that the base in pow is >0 !!! } double Area_of_Triangle(double leg_lenght_a, double leg_lenght_b, double leg_lenght_c) { // Hero's formula for the triangle area double part=(leg_lenght_a+leg_lenght_b+leg_lenght_c)/2.0; double area=sqrt(part*(part-leg_lenght_a)*(part-leg_lenght_b)*(part-leg_lenght_c)); return(area); }