Home > Backend Development > C++ > body text

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

王林
Release: 2023-09-01 18:25:02
forward
653 people have browsed it

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);
}
Copy after login

Output

Area is: 4.18867
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template