- 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

# C++ program to find two points from two lines who are not same

Suppose we have two ranges (l1, r1), (l2, r2) represents two lines on x-axis. l1 < r1 and l2 < r2. These segments may intersect, overlap or coincide with each other. We have to find two numbers a and b, such that a is in range (l1, r1) and b is in (l2, r2) and a and b are distinct.

So, if the input is like l1 = 2; r1 = 6; l2 = 3; r2 = 4, then the output will be a = 3, b = 4, other answers are also possible.

## Steps

To solve this, we will follow these steps −

if l1 is same as l2, then: (increase l1 by 1) return l1 and l2

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; void solve(int l1, int r1, int l2, int r2) { if (l1 == l2) l1++; cout << l1 << ", " << l2; } int main() { int l1 = 2; int r1 = 6; int l2 = 3; int r2 = 4; solve(l1, r1, l2, r2); }

## Input

2, 6, 3, 4

## Output

2, 3

- Related Questions & Answers
- C++ program to find whether only two parallel lines contain all coordinates points or not
- C Program to check if two strings are same or not
- C# program to check whether two sequences are the same or not
- Python - Make pair from two list such that elements are not same in pairs
- Program to check whether leaves sequences are same of two leaves or not in python
- C++ program to find two numbers from two arrays whose sum is not present in both arrays
- Program to Find the Shortest Distance Between Two Points in C++
- C program to calculate distance between two points
- Program to find minimum difference between two elements from two lists in Python
- Python program to find uncommon words from two Strings
- Java Program to check whether two Strings are an anagram or not.
- C program to compare if the two matrices are equal or not
- Program to check whether two sentences are similar or not in Python
- How to check if two data frames same or not in R?
- Program to form smallest number where no two adjacent digits are same in Python

Advertisements