Question

Heron's Formula for the area of a triangle with si Please help c++
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

/*method to calculate area of the triangle */
double area(double a,double b,double c){
double s=(a+b+c)/2; /*calculating s*/
/* calculating area */
double areaTriangle=s*(s-a)*(s-b)*(s-c);
return areaTriangle;/* returning area to main */
}
int main()
{double a,b,c;
/* Prompting user to enter 3 sides of the triangle */
cout << "Enter 1 side of the triangle : " << endl;
cin>>a;
cout << "Enter 2 side of the triangle : " << endl;
cin>>b;
cout << "Enter 3 side of the triangle : " << endl;
cin>>c;
/* calling area method and storing the returned result into variable areaTriangle */
double areaTriangle=area(a,b,c);
/* printing area */
cout<<"The area of a triangle with sides "<<a<<","<<b<<" and "<<c<<" is "<<areaTriangle<<endl;
return 0;
}

/*******OUTPUT**********
Enter 1 side of the triangle :
3   
Enter 2 side of the triangle :
4   
Enter 3 side of the triangle :
5   
The area of a triangle with sides 3,4 and 5 is 36   
*******OUTPUT************/

/* Note: Please ask in case of any doubt,thanks */

Add a comment
Know the answer?
Add Answer to:
Please help c++ Heron's Formula for the area of a triangle with sides a, b and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT