Related Articles
Slope of perpendicular to line
• Difficulty Level : Medium
• Last Updated : 28 Nov, 2019

You are given the slope of one line (m1) 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
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Suppose we are given two perpendicular line segments AB and CD. The slope of AB is m1 and line CD is m2 .

m1 * m2 = -1
From above, we can say
m2 = – 1/( m1 ) .

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 ``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;``}`

## 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));``    ``}``}`

## 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 `

## 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`

## PHP

 ``
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.

My Personal Notes arrow_drop_up