풀이 ¶
세변의 길이가 주어질때 삼각형의 내심원의 반지름을 구하는 문제이다.
헤론의 공식을 이용해 세변으로 넓이는 구하면
헤론의 공식을 이용해서 구한 넓이 = (내심원의 반지름 x 세변의 합)/2 로 구할 수 있다.
헤론의 공식을 이용해 세변으로 넓이는 구하면
소스 ¶
~cpp
#include <iostream>
#include <cmath>
using namespace std;
double a, b, c, halfSum;
void getRadius()
{
halfSum = (a+b+c)/2.0;
if(halfSum==0)
{
cout << "The radius of the round table is: 0.000"<<endl;
return;
}
cout << "The radius of the round table is: " << 1.0*sqrt(halfSum*(halfSum-a)*(halfSum-b)*(halfSum-c))/halfSum << endl;
}
int main()
{
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
cout.precision(3);
while(cin>>a>>b>>c)
getRadius();
return 0;
}










