#
I need to write a program in C++ that will calculate a triangle area from the Heron's formula.

1
by bituin

Log in to add a comment

by bituin

Log in to add a comment

#include <math.h>

using namespace std;

float Heron(float a, float b, float c){

float p=(a+b+c)/2;

return sqrt(p*(p-a)*(p-b)*(p-c));

}

int main(){

float a,b,c;

cout << "Enter a: ";

cin >> a;

cout << "Enter b: ";

cin >> b;

cout << "Enter c: ";

cin >> c;

if(a<=0 || b<=0 || c<=0){

cout << "All values must be greater than 0!\n";

system("pause");

return 1;

}

else{

cout << "Area of the triangle = " << Heron(a,b,c) << endl;

system("pause");

return 0;

}

}