1、验证输出参数是否符合要求

2、求出三角形面积

 

 

AreaMath.h
#include <math.h>
 
//验证输入的值是否符合要求
bool ValidateInputValue(double x,double y,double z)
{
       return x>0&&x>0&&z>0&&(x+y>z||x+z>y||y+z>x)?true:false;

}
//求出三角形的面积
double area(double x,double y,double z)
{
        
//三角形面积S=√x*(x-a)*(x-b)*(x-c)
        
//其中"√"是大根号,"x"为三角形周长的一半,a,b,c为边长
        double h=(x+y+z)/2;
        
return sqrt(h*(h-x)*(h-y)*(h-z));
}

 

 

 

MainCase.cpp
//引入头文件
#include <AreaMath.h>
#include 
<stdio.h>

int main(int argc, char* argv[])
{
        
ValidateInputValue(3,4,5)?printf("area is:%f", area(3,4,5)):printf("Error parameters");
        
return 0;
}

 

 

相关文章:

  • 2021-09-07
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
猜你喜欢
  • 2021-10-26
  • 2021-10-29
  • 2021-12-26
  • 2021-12-19
  • 2021-07-09
  • 2021-12-19
相关资源
相似解决方案