You are given the slope of one line (m_{1}) and you have to find the slope of another line which is perpendicular to the given line.

Examples:

Input : 5 Output : Slope of perpendicular line is : -0.20 Input : 4 Output : Slope of perpendicular line is : -0.25

Suppose we are given two perpendicular line segments AB and CD. The slope of AB is m_{1} and line CD is m_{2} .

m

_{1}* m_{2}= -1

From above, we can say

m_{2}= – 1/( m_{1}) .

**How does above formula work?**

Let slope of line AB be m1 and we need to find slope of line CD. Below diagram gives an idea about working of formula.

## C++

`// C++ program find slope of perpendicular line ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find ` `// the Slope of other line ` `double` `findPCSlope(` `double` `m) ` `{ ` ` ` `return` `-1.0 / m; ` `} ` ` ` `int` `main() ` `{ ` ` ` `double` `m = 2.0; ` ` ` `cout << findPCSlope(m); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to illustrate ... ` ` ` `import` `java.io.*; ` `import` `java.util.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to find ` ` ` `// the Slope of other line ` ` ` `static` `double` `findPCSlope(` `double` `m) ` ` ` `{ ` ` ` `return` `-` `1.0` `/ m; ` ` ` `} ` ` ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` ` ` `double` `m = ` `2.0` `; ` ` ` `System.out.println(findPCSlope(m)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 program find ` `# slope of perpendicular line ` ` ` `# Function to find ` `# the Slope of other line ` `def` `findPCSlope(m): ` ` ` ` ` `return` `-` `1.0` `/` `m ` ` ` `m ` `=` `2.0` `print` `(findPCSlope(m)) ` ` ` `# This code is contributed ` `# by Smitha ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find Slope ` `// of perpendicular to line ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to find ` ` ` `// the Slope of other line ` ` ` `static` `double` `findPCSlope(` `double` `m) ` ` ` `{ ` ` ` `return` `-1.0 / m; ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` ` ` `double` `m = 2.0; ` ` ` `Console.Write(findPCSlope(m)); ` ` ` `} ` `} ` ` ` `// This code is contributed by nitin mittal ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program find slope ` `// of perpendicular line ` ` ` `// Function to find the ` `// Slope of other line ` `function` `findPCSlope(` `$m` `) ` `{ ` ` ` `return` `-1.0 / ` `$m` `; ` `} ` ` ` ` ` `// Driver Code ` ` ` `$m` `= 2.0; ` ` ` `echo` `findPCSlope(` `$m` `); ` ` ` `// This code is contributed by anuj_67 ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

-0.5

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.

## Recommended Posts:

- Slope of the line parallel to the line with the given slope
- Perpendicular distance between a point and a Line in 2 D
- Find foot of perpendicular from a point in 2 D plane to a Line
- Length of the perpendicular bisector of the line joining the centers of two circles
- Program to find slope of a line
- Find points at a given distance on a line of given slope
- Find the foot of perpendicular of a point in a 3 D plane
- Count of Right-Angled Triangle formed from given N points whose base or perpendicular are parallel to X or Y axis
- How to check if two given line segments intersect?
- Given n line segments, find if any two segments intersect
- Count maximum points on same line
- Klee's Algorithm (Length Of Union Of Segments of a line)
- Line Clipping | Set 1 (Cohen–Sutherland Algorithm)
- Find an Integer point on a line segment with given two ends
- Represent a given set of points by the best possible straight line
- Program to find line passing through 2 Points
- Reflection of a point about a line in C++
- Check if a line touches or intersects a circle
- One line function for factorial of a number
- Section formula (Point that divides a line in given ratio)

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.