找出三角形的内切圆半径的 C++ 程序


本教程中,我们将讨论一个程序,用于求出给定三角形的内切圆半径。

为此,我们将获得特定三角形各边的信息,我们的任务是找出该三角形内切圆的半径。

求出内切圆半径的公式为:

三角形面积/三角形半周长

示例

#include <bits/stdc++.h>
using namespace std;
//calculating the radius of incircle
float calc_radius(float a, float b, float c) {
   if (a < 0 || b < 0 || c < 0)
      return -1;
   //half perimeter of triangle
   float p = (a + b + c) / 2;      
   //area of triangle
   float area = sqrt(p * (p - a) * (p - b) * (p - c));
   float radius = area / p;
   // Return the radius
   return radius;
}
int main() {
   float a = 4, b = 7, c = 9;
   cout << calc_radius(a, b, c) << endl;
   return 0;
}

输出

1.34164

更新时间:2019 年 11 月 21 日

193 次浏览

开启你的 职业生涯

完成课程,获得认证

开始
广告
© . All rights reserved.