luc015.c (1227B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Given three points (x1, y1), (x2, y2), and (x3, y3), 8 write a program to check if the three poins fall on one straight line. */ 9 /* Let Us C, Chap- 3, Page - 53, Qn No.: f(f) */ 10 11 #include <stdio.h> 12 #include <math.h> 13 #define EPSILON 0.0001 14 // Define a small tolerance value (EPSILON) for safe floating-point comparison 15 // This is critical because of minor rounding errors in computer arithmetic. 16 int main() 17 { 18 double x1, x2, x3, y1, y2, y3, area; 19 printf("Enter the point A(x1, y1) : "); 20 scanf("%lf %lf", &x1, &y1); 21 printf("Enter the point B(x2, y2) : "); 22 scanf("%lf %lf", &x2, &y2); 23 printf("Enter the point C(x3, y3) : "); 24 scanf("%lf %lf", &x3, &y3); 25 area = 0.5 * ((x1 * (y2 - y3)) + (x2 * (y3 - y1)) + (x3 * (y1 - y2))); 26 if (fabs(area) < EPSILON) // abs() for integer, fabs() for float, double 27 printf("\nA(%g, %g), B(%g, %g) and C(%g, %g) points fall on one straight line.", x1, y1, x2, y2, x3, y3); 28 else 29 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); 30 return 0; 31 }