Given an integer m which is the slope of a line, the task is to find the slope of the line which is parallel to the given line.
Input: m = 2
Input: m = -3
Let P and Q be two parallel lines with equations y = m1x + b1, and y = m2x + b2 respectively.Here m1 and m2 are the slopes of the lines respectively. Now as the lines are parallel, they don’t have any intersecting point, and hence there will be no system of solutions for the lines. So, let us try to solve the equations,
For y, m1x + b1 = m2x + b2
m1x – m2x = b2 – b1
x(m1 – m2) = b2 – b1
The only way there can be no solution for x is for m1 – m2 to be equal to zero.
m1 – m2 = 0
This gives us m1 = m2 and the slopes are equal.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find points at a given distance on a line of given slope
- Find the slope of the given number
- Count of Squares that are parallel to the coordinate axis from the given set of N points
- Number of lines from given N points not parallel to X or Y axis
- Find the equation of plane which passes through two points and parallel to a given axis
- Count of Right-Angled Triangle formed from given N points whose base or perpendicular are parallel to X or Y axis
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Maximum Squares possible parallel to both axes from N distinct points
- Program to check if the points are parallel to X axis or Y axis
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Find whether only two parallel lines contain all coordinates points or not
- Distance between two parallel lines
- Maximum number of region in which N non-parallel lines can divide a plane
- Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively
- Missing vertex among N axis-parallel rectangles
- How to check if two given line segments intersect?
- Given n line segments, find if any two segments intersect
- Represent a given set of points by the best possible straight line
- Section formula (Point that divides a line in given ratio)
- Check whether the point (x, y) lies on a given line