zoukankan      html  css  js  c++  java
  • 如何求出三角形的面积

    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;
    }
  • 相关阅读:
    G
    ZOJ 3782
    23.内存池
    22.boost图模板
    21.boost Ford最短路径算法(效率低)
    20.boost dijkstra最短路径算法
    19.boost A*算法
    18.boost 图的拓扑排序
    17.广度优先遍历bfs
    16.boost图深度优先遍历DFS
  • 原文地址:https://www.cnblogs.com/magic_evan/p/1847525.html
Copyright © 2011-2022 走看看