# Slope of the line parallel to the line with the given slope

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.

**Examples:**

Input:m = 2

Output:2

Input:m = -3

Output:-3

**Approach:**

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 forxis form1 – m2to be equal to zero.

m1 – m2 = 0

This gives usm1 = m2and the slopes are equal.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the slope ` `// of the line which is parallel to ` `// the line with the given slope ` `double` `getSlope(` `double` `m) ` `{ ` ` ` `return` `m; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `double` `m = 2; ` ` ` `cout << getSlope(m); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GfG ` `{ ` ` ` `// Function to return the slope ` `// of the line which is parallel to ` `// the line with the given slope ` `static` `double` `getSlope(` `double` `m) ` `{ ` ` ` `return` `m; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `double` `m = ` `2` `; ` ` ` `System.out.println(getSlope(m)); ` `} ` `} ` ` ` `// This code is contributed by Code_Mech. ` |

*chevron_right*

*filter_none*

## Python3

# Python3 implementation of the approach

# Function to return the slope

# of the line which is parallel to

# the line with the given slope

def getSlope(m):

return m;

# Driver code

m = 2;

print(getSlope(m));

# This code is contributed

# by Akanksha Rai

## C#

`// C# implementation of the approach ` `class` `GFG ` `{ ` ` ` `// Function to return the slope ` `// of the line which is parallel to ` `// the line with the given slope ` `static` `double` `getSlope(` `double` `m) ` `{ ` ` ` `return` `m; ` `} ` ` ` `// Driver code ` `static` `void` `Main() ` `{ ` ` ` `double` `m = 2; ` ` ` `System.Console.Write(getSlope(m)); ` `} ` `} ` ` ` `// This code is contributed by mits ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the slope ` `// of the line which is parallel to ` `// the line with the given slope ` `function` `getSlope(` `$m` `) ` `{ ` ` ` `return` `$m` `; ` `} ` ` ` `// Driver code ` `$m` `= 2; ` `echo` `getSlope(` `$m` `); ` ` ` `// This code is contributed by Ryuga ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

2

## Recommended Posts:

- Slope of perpendicular to line
- Program to find slope of a line
- Find points at a given distance on a line of given slope
- Find the slope of the given number
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Find the other end point of a line with given one end and mid
- Chain Code for 2D Line
- Reflection of a point about a line in C++
- Check if a line passes through the origin
- Perpendicular distance between a point and a Line in 2 D
- Bresenham's Algorithm for 3-D Line Drawing
- Check whether the point (x, y) lies on a given line
- Represent a given set of points by the best possible straight line
- Program to find the mid-point of a line
- Direction of a Point from a Line Segment

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.