- 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

# Number of ordered points pair satisfying line equation in C++

The line equation that should be satisfied is y = mx + c. Given an array, m, and c, we have to find the number of order points satisfying the line equation. Let's see an example.

**Input**

arr = [1, 2, 3] m = 1 c = 1

**Output**

2

The pairs satisfying the line equation are

2 1 3 2

## Algorithm

- Initialise the array, m, and c.
- Write two loops to get all pairs from the array.
- Check whether the pair is satisfying the line equation or not.
- We can check the whether the equation is satisfied or not by substituting the values into the line equation.
- If the pair satisfies the line equation, then increment the count.

- Return the count.

## Implementation

Following is the implementation of the above algorithm in C++

#include <bits/stdc++.h> using namespace std; bool isSatisfyingLineEquation(int arr[], int i, int j, int m, int c) { if (i == j) { return false; } return arr[j] == m * arr[i] + c; } int getOrderedPointsPairCount(int arr[], int n, int m, int c) { int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (isSatisfyingLineEquation(arr, i, j, m, c)) { count++; } } } return count; } int main() { int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int n = 10; int m = 1, c = 1; cout << getOrderedPointsPairCount(arr, n, m, c) << endl; return 0; }

## Output

If you run the above code, then you will get the following result.

9

- Related Questions & Answers
- Closest Pair of Points Problem
- Count distinct points visited on the number line in C++
- Program to count number of points that lie on a line in Python
- Number of Integral Points between Two Points in C++
- C++ Program to Find Closest Pair of Points in an Array
- Program to find equation of a plane passing through 3 points in C++
- Max Points on a Line in C++
- Number of non-negative integral solutions of sum equation in C++
- Find number of endless points in C++
- Program to find number of solutions in Quadratic Equation in C++
- Find number of solutions of a linear equation of n variables in C++
- Find the number of solutions to the given equation in C++
- Program to find out the number of integral coordinates on a straight line between two points in Python
- Count number of ordered pairs with Even and Odd Product in C++
- Count number of ordered pairs with Even and Odd Sums in C++

Advertisements