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.