The Area of an Arbitrary Triangle-任意三角形的面积
2014-08-31 20:55
423 查看
The Area of an Arbitrary Triangle-任意三角形的面积,允许重复计算:
//The Area of an Arbitrary Triangle-任意三角形的面积 #include<iostream> #include<cmath> using namespace std; bool IsTriangle(double a,double b,double c); void areafun(double a,double b,double c,double& area,double& s); int main() { double a,b,c,s,area; char ans; do{ cout<<"Enter the three length of the Triangle:\n"; cin>>a>>b>>c; if(IsTriangle(a,b,c)) areafun(a,b,c,area,s); else cout<<"The three length are error!\n"; cout<<"Do you want again?"; cin>>ans; }while('Y' == ans || 'y' == ans); return 0; } bool IsTriangle(double a,double b,double c) { if((a+b>c && a+c>b && b+c>a && abs(a-b)<c && abs(a-c)<b && abs(b-c)<a) ) return 1; return 0; } void areafun(double a,double b,double c,double& area,double& s) { s = (a+b+c)/2; area = sqrt(s*(s-a)*(s-b)*(s-c)); cout<<"The area of the Triangle is:"<<area<<endl; }结果:
Enter the three length of the Triangle: 3 4 5 The area of the Triangle is:6 Do you want again?y Enter the three length of the Triangle: 3 4 4 The area of the Triangle is:5.56215 Do you want again?y Enter the three length of the Triangle: 3 4 9 The three length are error! Do you want again?y Enter the three length of the Triangle: 4 4 4 The area of the Triangle is:6.9282 Do you want again?
相关文章推荐
- How to build the topology of an OSPF area
- [SPOJ CIRU]The area of the union of circles(自适应Simpson积分求圆并面积)
- hdu---(Tell me the area)(几何/三角形面积以及圆面积的一些知识)
- [省选前题目整理][SPOJ CIRU]The area of the union of circles(自适应Simpson积分求圆并面积)
- SPOJ CIRU(The area of the union of circles-圆的面积并)
- SUNDIALS-CLN:An Arbitrary Precision Extension of the CVODE Library
- 任意输入三条边(a,b,c实型),若能构成三角形,则计算并输出其面积,否则输出标志“No Triangle!”。
- SPOJ CIRU - The area of the union of circles (圆的面积并)
- SPOJ - CIRU The area of the union of circles (圆形面积并)
- SPOJ 8073 CIRU - The area of the union of circles(圆面积并)
- C++上机报告,任意输入三条边(a,b,c实型),若能构成三角形,则计算并输出其面积,否则输出标No Triangle!
- 1437 [CA1006]The area of triangle
- SUNDIALS-CLN:An Arbitrary Precision Extension of the CVODE Library
- Check if the key is composed of an arbitrary number of concatenations of strings from the dictionar
- 问题三十四: 任意输入三条边(a,b,c实型),若能构成三角形,则计算并输出其面积,否则输出标志“No Triangle!”。
- Why is the size of an empty class not zero?
- Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.
- Matt Meleski's .Net Blog - The ABC's of .NET : Constructing BizTalk 2004 XML Messages (In an Orchestration) - Choices
- Tooltip 显示大图的代码(show an enlarge image in the tooltip of the image)
- Study on the Reconstruction of Ancient Great Wall of Shanhaiguan Area