Point of intersection of two lines

Write a program that reads a, b, c, p, q and r. Let ax + by + c = 0 and px + qy + r = 0 be the equations
of two lines. Print their point of intersection.

Program:

#include<stdio.h>
int main()
{
      int a,b,c;
      int p,q,r;
      printf("a,b,c: ");
      scanf("%d%d%d",&a,&b,&c);
      printf("p,q,r: ");
      scanf("%d%d%d",&p,&q,&r);
      int x,y;
      x=(b*r-q*c)/(a*q-b*p);
      y=(p*c-a*r)/(a*q-b*p);
      printf("point of intersection (x,y)=(%d,%d)",x,y);
      return 0;
}

Sample input:

a,b,c: 4 8 12
p,q,r: 2 7 3
Sample output:
point of intersection (x,y)=(-5,1)



No comments: