C++ program to find out the area of triangle when three sides a, b and c of the triangle are given, using appropriate statements to input the values of a, b and c from the keyboard. The formula for the area of triangle is area = sqrt(s(s-a)(s-b)(s-c)) where s = (a+b+c) / 2: C++

 C++

#include <iostream>
#include <math.h>

using namespace std;

int main() {
  // Declare variables
  float a, b, c, s, area;

  // Get the sides of the triangle from the user
  cout << "Enter the sides of the triangle: ";
  cin >> a >> b >> c;

  // Calculate the semi-perimeter
  s = (a + b + c) / 2;

  // Calculate the area of the triangle
  area = sqrt(s * (s - a) * (s - b) * (s - c));

  // Print the area of the triangle
  cout << "The area of the triangle is: " << area << endl;

  return 0;
}

To run this program, you can save it as a .cpp file and compile it using a C++ compiler. For example, on Linux or macOS, you can use the following command to compile the program:

g++ -o program program.cpp

Once the program is compiled, you can run it by typing the following command:

./program

For example, if you enter 3, 4, and 5 as the sides of the triangle, the program will print the following output:

Enter the sides of the triangle: 3 4 5
The area of the triangle is: 6

I hope this helps! Let me know if you have any other questions.

Copyright © 2025 AWS Tutorials | Distributed by Blogger Templates | Designed by OddThemes