বৃত্তের ব্যাসের দুটি এন্ডপয়েন্ট (x1,y1) এবং (x2,y2) দেওয়া আছে। বৃত্তের কেন্দ্র বের করতে হবে। সূত্র: মিডপয়েন্ট = ((x1+x2)/2, (y1+y2)/2)।
উদাহরণ
#include <iostream>
using namespace std;
class Point {
public:
float x, y;
Point(float x, float y) : x(x), y(y) {}
void display() { cout << "(" << x << ", " << y << ")"; }
};
Point center(Point p1, Point p2) {
float x = (p1.x + p2.x) / 2;
float y = (p1.y + p2.y) / 2;
return Point(x, y);
}
int main() {
Point p1(-9.0, 3.0), p2(5.0, -7.0);
Point res = center(p1, p2);
cout << "Center is at: ";
res.display();
return 0;
}
আউটপুট
Center is at: (-2, -2)