- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given coordinates two points A and B on the coordinate plane. Our task is to create a program to find line passing through 2 Points in C++.

To find the line, we need to use the equation of the line and put the solution using the coordinates.

**Let’s take an example to understand the problem**−

Input: A = (3, 3) B = (6, 1)

**Output**: 2x + 3y = 15

To find the equation of the line, we will use the general equation of line −

ax + by = c

This has to be satisfied by both the points A(x1, y1) and B(x2, y2)

The will make the equations,

ax1 + by1 = c

ax2 + by2 = c

Now, as c is common for both the equations we have

ax1 + by1 = ax2 + by2

=> ax1 - ax2 = by2 - by1

On equating we get,

$$a = (y2 - y1)$$ $$b = (x1 - x2)$$

c will be found using the equation,

$$ax1 + by1 = c$$

So, this is the equation for the equation of the line,

$$a = (y2 - y1)$$ $$b = (x1 - x2)$$ $$c = ax1 + by1$$

#include <iostream> using namespace std; void findLine(int points[2][2]) { int a = points[1][1] - points[0][1]; int b = points[0][0] - points[1][0]; int c = a*points[0][0] + b*points[0][1]; cout<<"("<<a<<"x) + ("<<b<<"y) = ("<<c<< } int main() { int points[2][2] = {{5, 9}, {1, 4}}; cout<<"The equation of line is "; findLine(points); return 0; }

The equation of line is (-5x) + (4y) = (11)

- Related Questions & Answers
- Program to find equation of a plane passing through 3 points in C++
- How to create a line that passes through specified points in an R plot?
- Max Points on a Line in C++
- Maximum distinct lines passing through a single point in C
- C++ Program to Find Number of Articulation points in a Graph
- C++ Program to Find Closest Pair of Points in an Array
- Program to Find the Shortest Distance Between Two Points in C++
- Program to find slope of a line in C++
- Find 2^(2^A) % B in C++
- Program to find out is a point is reachable from the current position through given points in Python
- How to find the difference between regression line and the points in R?
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++
- C program to find amount of volume passed through a tunnel
- Program to find last two digits of 2^n in C++
- Count distinct points visited on the number line in C++

Advertisements