- 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 two points A and B, starting and ending point of a line. Our task is to create a program to find the mid-point of a line in C++.

**Problem Description** − Here, we have a line with starting and ending points A(x1, y1) and B(x2, y2). And we need to find the mid-point of the line.

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

a(x1, y1) = (4, -5) b(x2, y2) = (-2, 6)

(1, 0.5)

(x1 + x2)/2 = 4 - 2 / 2 = 1 (y1 + y2)/2 = -5 + 6 / 2 = 0.5

To solve the problem, a simple method is using the geometrical formula for the mid of a line. The formula is given by,

Mid = ( ((x1 + x2)/2), ((y1 + y2)/2) )

**Program to illustrate the working of our solution,**

#include<iostream> using namespace std; int main() { float point[2][2] = {{-4, 5}, {-2, 6}}; float midX = (float)(( point[0][0] + point[1][0])/2); float midY = (float)(( point[0][1] + point[1][1])/2); cout<<"The mid-points are ("<<midX<<" , "<<midY<<")"; return 0; }

The mid-points are (-3 , 5.5)

- Related Questions & Answers
- C++ Program to Show the Duality Transformation of Line and Point
- C++ Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line
- Program to find slope of a line in C++
- Find foot of perpendicular from a point in 2D plane to a Line in C++
- Program to find the Break Even Point in C++
- Program to find the highest altitude of a point in Python
- Find Corners of Rectangle using mid points in C++
- Program to find GCD of floating point numbers in C++
- Python program to find the Decreasing point in a List
- C++ program to find first collision point of two series
- C++ program to find the best fit rectangle that covers a given point
- Program to find the number of possible position in a line in Python
- Write a one line C function to round floating point numbers
- Find intersection point of lines inside a section in C++
- Mid-Square hashing in C++.

Advertisements