- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to find the Radius of the incircle of the triangle
In this tutorial, we will be discussing a program to find the radius of the incircle of a given triangle.
For this, we will be provided with the sides of a particular triangle and our task is to find the radius of the incircle in that triangle.
The formula for finding the radius of incircle is
area of the triangle/half perimeter of the triangle
Example
#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; }
OUTPUT
1.34164
Advertisements