Given a straight line with equation coefficients as **a**, **b** **& c**(ax + by + c = 0), the task is to find the area of the triangle formed by the axes of co-ordinates and this straight line.

**Examples:**

Input:a = -2, b = 4, c = 3Output:0.5625Input:a = 4, b = 3, c = 12Output:6

**Approach**:

- Let
**PQ**be the straight line having**AB**, the line segment between the axes.

The equation is,

**ax + by + c = 0** - so, in intercept form it can be expressed as,

**x/(-c/a) + y/(-c/b) = 1** - So, the x-intercept =
**-c/a**

the y-intercept =**-c/b** - So, it is very clear now the base of the triangle
**AOB**will be**-c/a**

and the base of the triangle**AOB**will be**-c/b** - So, area of the triangle

Below is the implementation of the above approach:

## C++

`// C++ program area of triangle ` `// formed by the axes of co-ordinates ` `// and a given straight line ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find area ` `double` `area(` `double` `a, ` `double` `b, ` `double` `c) ` `{ ` ` ` `double` `d = ` `fabs` `((c * c) / (2 * a * b)); ` ` ` `return` `d; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `double` `a = -2, b = 4, c = 3; ` ` ` `cout << area(a, b, c); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program area of triangle ` `// formed by the axes of co-ordinates ` `// and a given straight line ` ` ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find area ` `static` `double` `area(` `double` `a, ` `double` `b, ` `double` `c) ` `{ ` ` ` `double` `d = Math.abs((c * c) / (` `2` `* a * b)); ` ` ` `return` `d; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` ` ` `double` `a = -` `2` `, b = ` `4` `, c = ` `3` `; ` ` ` `System.out.println(area(a, b, c)); ` `} ` `} ` ` ` `// This code is contributed by ajit. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program area of triangle ` `# formed by the axes of co-ordinates ` `# and a given straight line ` ` ` `# Function to find area ` `def` `area(a, b, c): ` ` ` ` ` `d ` `=` `abs` `((c ` `*` `c) ` `/` `(` `2` `*` `a ` `*` `b)) ` ` ` `return` `d ` ` ` `# Driver code ` `a ` `=` `-` `2` `b ` `=` `4` `c ` `=` `3` `print` `(area(a, b, c)) ` ` ` `# This code is contributed ` `# by mohit kumar ` |

*chevron_right*

*filter_none*

## C#

`// C# program area of triangle ` `// formed by the axes of co-ordinates ` `// and a given straight line ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find area ` `static` `double` `area(` `double` `a, ` `double` `b, ` `double` `c) ` `{ ` ` ` `double` `d = Math.Abs((c * c) / (2 * a * b)); ` ` ` `return` `d; ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main () ` `{ ` ` ` ` ` `double` `a = -2, b = 4, c = 3; ` ` ` `Console.WriteLine (area(a, b, c)); ` `} ` `} ` ` ` `// This code is contributed by akt_mit. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program area of triangle ` `// formed by the axes of co-ordinates ` `// and a given straight line ` ` ` `// Function to find area ` `function` `area(` `$a` `, ` `$b` `, ` `$c` `) ` `{ ` ` ` `$d` `= ` `abs` `((` `$c` `* ` `$c` `) / (2 * ` `$a` `* ` `$b` `)); ` ` ` `return` `$d` `; ` `} ` ` ` `// Driver code ` `$a` `= -2; ` `$b` `= 4; ` `$c` `= 3; ` ` ` `echo` `area(` `$a` `, ` `$b` `, ` `$c` `); ` ` ` `// This code is contributed by Ryuga ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

0.5625

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:

- Equation of straight line passing through a given point which bisects it into two equal line segments
- Check if a right-angled triangle can be formed by the given coordinates
- Check whether a straight line can be formed using N co-ordinate points
- Check if a right-angled triangle can be formed by moving any one of the coordinates
- Find the coordinates of a triangle whose Area = (S / 2)
- Count squares of unique dimensions possible from given Straight Lines parallel to the axes
- Represent a given set of points by the best possible straight line
- Length of the normal from origin on a straight line whose intercepts are given
- Program to find the Type of Triangle from the given Coordinates
- Find coordinates of the triangle given midpoint of each side
- Find minimum area of rectangle with given set of coordinates
- Straight-line Number
- Puzzle | Place numbers 1 to 9 in a Circle such that sum of every triplet in straight line is 15
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Check if right triangle possible from given area and hypotenuse
- Minimum height of a triangle with given base and area
- Slope of the line parallel to the line with the given slope
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Maximum count of Equilateral Triangles that can be formed within given Equilateral Triangle
- Count of Right-Angled Triangle formed from given N points whose base or perpendicular are parallel to X or Y axis

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.