Ibrahim Filandra - 1 year ago 89

C Question

I'm trying to create a program in which you input coefficients of two lines (a1x+b1 and a2x+b2) and it calculates if they are coincident, parallel or if they intersect, it finds the point of intersection. I can't successfully compare the coefficients and the output of the program is always like this: They intersect at point (0.00,0.00). What am I doing wrong?

`#include <stdio.h>`

#include <math.h>

#define epsilon 0.001

int main() {

float a1,b1,a2,b2;

float x=0;

float y=0;

printf("Insert a1,b1,a2,b2: ");

scanf("%f %f %f %f", &a1,&b1,&a2,&b2);

if (fabs(a1-a2)<epsilon && fabs(b1-b2)<epsilon) {

printf("Coincident");

}

else if(fabs(a1-a2)<epsilon && fabs(b1-b2)>epsilon) {

printf("Parallel");

}

else if (((fabs(a1-a2)>epsilon && fabs(b1-b2)>epsilon) || (fabs(a1-a2)>epsilon && fabs(b1-b2)<epsilon)) )

{

x=(b2-b1)/(a1-a2);

y=a1*x+b1;

printf("They intersect at point (%.2f, %.2f)", x, y);

}

return 0;

}

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**