0% found this document useful (0 votes)
64 views1 page

Finding Its Intersection Point

The document provides a coding question and test code to find the intersection point of two lines. It asks the user to input the coordinates of two points for each line. It then calculates the slope of each line and sets their y-values equal to find the x-value of the intersection point. It uses this x-value to also find the corresponding y-value of intersection. The code prints the x and y coordinates of the intersection point.

Uploaded by

Pranay Mudhiraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views1 page

Finding Its Intersection Point

The document provides a coding question and test code to find the intersection point of two lines. It asks the user to input the coordinates of two points for each line. It then calculates the slope of each line and sets their y-values equal to find the x-value of the intersection point. It uses this x-value to also find the corresponding y-value of intersection. The code prints the x and y coordinates of the intersection point.

Uploaded by

Pranay Mudhiraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

FACE TCS Ninja - Coding_6

TEST CODE : TCS Ninja -


Coding_6
Total number of question : 1
Test duration (min) : 20 min
Correct attempt (mark) : NA
Wrong attempt (mark) : NA

CODING

Given two lines, write Program for finding its intersection point

#include <stdio.h>

int main()
{
float x1, y1, x2, y2;
scanf("%f,%f\n%f,%f", &x1, &y1, &x2, &y2);

float x3,y3,x4,y4;
scanf("%f,%f\n%f,%f", &x3, &y3, &x4, &y4);

float m1 = (y2-y1)/(x2-x1);
float m2 = (y4-y3)/(x4-x3);

// Line 1
// y = y1 + m * (x - x1);
// y = y1 + m * (x - x1);
// y = m1*x + y1 - m1 * x1

// Line 2
// y = y1 + m * (x - x1);
// y = y3 + m2 * (x - x3);
// y = m2*x + y3 - m2 * x3

// Solving line 1 and line 2 eqn


float x_intersection = (y1 - m1 * x1 - y3 + m2 * x3)/(m2-m1);
float y_intersection = y1 + m1 * (x_intersection - x1);

printf("%0.2f,%0.2f", x_intersection, y_intersection);

return 0;
}

______________________________________________________________________________________________________
Focus Academy for Career Enhancement Page 1 of 1

You might also like