Friday, 19 August 2016

Problem Statement 3:
Given two equations of lines , find whether they are coincident, parallel or intersecting lines.
For example :
a1*x+b1*y+c1=0
a2*x+b2*x+c2=0
If lines are coincident then print "coincident". If lines are parallel then print "parallel". If lines are
intersecting then print "intersecting".
Input:
First line contains t which specifies the number of test cases. Following t lines contain 2*t space
separated constants as a1,b1,c1 for first line and a2,b2,c2 for second line.
Output:
Print either "coincident","parallel" or "intersecting" based on the given pair of equations of the lines
in each of the t lines.
Constraints:
1<=t<=10000
0.0000001<=a1,b1,c1,a2,b2,c2<=1000000 or -0.0000001>=a1,b1,c1,a2,b2,c2>=-1000000
Sample test cases:
Input:
3
1 2 3
4 8 10
3 4 5
6 8 10
7 4 3
1 4 7
Output:
parallel
coincident
intersecting

 

Solution:

#include<stdio.h>
int main()
{
    int i,test;
    float a,b,c,p,q,r;
    scanf("%d",&test);
    for( i=1;i<=test;i++)
    {
        scanf("%f %f %f",&a,&b,&c);
        scanf("%f %f %f",&p,&q,&r);
        if(((a/p) == (b/q)) && ((c/r)==(a/p)))
        printf("coincident");
        else if (((a/b) == (p/q)))
        {
        printf("parallel");
        }
        else
        printf("intersecting");
    printf("\n");
    }
}

No comments:

Post a Comment