#include #include int main() { double a, b; printf("Enter the two perpendicular sides\n"); printf("a: "); scanf("%lf", &a); printf("b: "); scanf("%lf", &b); printf("The area is %lf\n", 0.5*a*b); double hypotenuse = sqrt(a*a+b*b); printf("Hypotenuse: %lf\n", hypotenuse); /* Assuming equation of line as y=mx+c which passes through two points (0,b) and (a,0) we get: m = -b/a c = b Now, dist of point (0,0) from line is: b/sqrt(1+m^2) */ double m = -b/a; double height = b/sqrt(1+m*m); printf("The area (using height) is %lf\n", 0.5*hypotenuse*height); if( 0.5*a*b == 0.5*hypotenuse*height ) printf("Same"); else { printf("Different"); /* The areas may apppear equal, but they could be different at later digits. This can be seen by using the == operator. The reason is that real numbers of arbitrary precision cannot be represented on a computer. So irrational numbers, often encountered while using sqrt() will lose some precision. So when you calculate the area, the area (though appearing same) could be different. Test case: 5,12 */ } }