#includeusingnamespacestd;floatarea(floata){ if(a<0)//ifthevalueisnegativeitisinvalid return-1; "/> #includeusingnamespacestd;floatarea(floata){ if(a<0)//ifthevalueisnegativeitisinvalid return-1; ">

Home >Backend Development >C++ >In the C program, calculate the area of ​​the inscribed circle of an equilateral triangle

In the C program, calculate the area of ​​the inscribed circle of an equilateral triangle

王林
王林forward
2023-09-01 18:25:02660browse

Here we will see the area of ​​the circle inscribed in an equilateral triangle. The side of the triangle is "a".

In the C program, calculate the area of ​​the inscribed circle of an equilateral triangle

The area of ​​an equilateral triangle-

In the C program, calculate the area of ​​the inscribed circle of an equilateral triangle

The half-perimeter of the triangle is-

In the C program, calculate the area of ​​the inscribed circle of an equilateral triangle

So the radius of the circle is -

In the C program, calculate the area of ​​the inscribed circle of an equilateral triangle

Example

#include <iostream>
#include <cmath>
using namespace std;
float area(float a) {
   if (a < 0 ) //if the value is negative it is invalid
      return -1;
   float area = 3.1415 * (a/(2*sqrt(3))) * (a/(2*sqrt(3)));
   return area;
}
int main() {
   float a = 4;
   cout << "Area is: " << area(a);
}

Output

Area is: 4.18867

The above is the detailed content of In the C program, calculate the area of ​​the inscribed circle of an equilateral triangle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete