C++ Exercises: Prints the central coordinate and the radius of a circumscribed circle of a triangle
C++ Basic: Exercise-67 with Solution
Write a C++ program that prints the central coordinate and the radius of a circumscribed circle of a triangle. This circle is created from three points on the plane surface.
Pictorial Presentation:

Sample Solution:
C++ Code :
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
double a, b, c, x1, y1, x2, y2, x3, y3, xp, yp, d, radius;
while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3) {
a = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
b = sqrt((x3 - x1)*(x3 - x1) + (y3 - y1)*(y3 - y1));
c = sqrt((x3 - x2)*(x3 - x2) + (y3 - y2)*(y3 - y2));
radius = (a*b*c) / (sqrt((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c)));
d = 2*(x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2));
xp = ((x1*x1 + y1*y1)*(y2-y3) + (x2*x2 + y2*y2)*(y3-y1) + (x3*x3 + y3*y3)*(y1-y2))/d;
yp = ((x1*x1 + y1*y1)*(x3-x2) + (x2*x2 + y2*y2)*(x1-x3) + (x3*x3 + y3*y3)*(x2-x1))/d;
cout << fixed << setprecision(3) << "Central coordinate of the circumscribed circle: (" << xp << ", " << yp << ")\nRadius: " << radius << endl;
}
return 0;
}
Sample Output:
Sample input : 6 9 7 Sample Output: 7 9 6
Flowchart:

C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C++ program to add all the numbers from 1 to a given number.
Next: Write a C++ program to read seven numbers and sorts them in descending order.
What is the difficulty level of this exercise?
C++ Programming: Tips of the Day
Why is there no std::stou?
The most pat answer would be that the C library has no corresponding "strtou", and the C++11 string functions are all just thinly veiled wrappers around the C library functions: The std::sto* functions mirror strto*, and the std::to_string functions use sprintf.
Ref: https://bit.ly/3wtz2qA
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook