luc015.c (1091B)
1 /* Given three points (x1, y1), (x2, y2), and (x3, y3), 2 write a program to check if the three poins fall on one straight line. */ 3 /* Let Us C, Chap- 3, Page - 53, Qn No.: f(f) */ 4 5 #include <stdio.h> 6 #include <math.h> 7 #define EPSILON 0.0001 8 // Define a small tolerance value (EPSILON) for safe floating-point comparison 9 // This is critical because of minor rounding errors in computer arithmetic. 10 int main() 11 { 12 double x1, x2, x3, y1, y2, y3, area; 13 printf("Enter the point A(x1, y1) : "); 14 scanf("%lf %lf", &x1, &y1); 15 printf("Enter the point B(x2, y2) : "); 16 scanf("%lf %lf", &x2, &y2); 17 printf("Enter the point C(x3, y3) : "); 18 scanf("%lf %lf", &x3, &y3); 19 area = 0.5 * ((x1 * (y2 - y3)) + (x2 * (y3 - y1)) + (x3 * (y1 - y2))); 20 if (fabs(area) < EPSILON) // abs() for integer, fabs() for float, double 21 printf("\nA(%g, %g), B(%g, %g) and C(%g, %g) points fall on one straight line.", x1, y1, x2, y2, x3, y3); 22 else 23 printf("\nA(%g, %g), B(%g, %g) and C(%g, %g) points doesn't fall on one straight line.", x1, y1, x2, y2, x3, y3); 24 return 0; 25 }