zoukankan      html  css  js  c++  java
  • rwkj 1363 正方形 长方形 三角形面积


    C++:重载函数2(计算面积)
    时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
    总提交:370 测试通过:241

    描述


    定义重载函数area(),分别计算正方形、长方形和三角形的面积。


    输入


    共计有3行。

    第1行有一个实数,为正方形的边长;

    第2行有二个实数,为长方形的两条边长;

    第3行有三个实数,为三角形的三边长。


    输出

    正方形、长方形和三角形的面积(保留3位小数)。

    样例输入

    3.5
    4.2 5.62
    3.0 4.0 5.0

    样例输出

    12.250
    23.604
    6.000


    #include<iostream>
    #include<iomanip>
    #include<cmath>
    using namespace std;
    double area(double a)
    {
    return a*a;
    }
    double area(double a,double b)
    {
    return a*b;
    }
    double area(double a,double b,double c)
    {
    double s;
    s=(a+b+c)/2;
    return sqrt(s*(s-a)*(s-b)*(s-c));
    }
    int main()
    {
    double a,b1,b2,c1,c2,c3;
    cin>>a;
    cin>>b1>>b2;
    cin>>c1>>c2>>c3;
    cout<<fixed<<setprecision(3)<<area(a)<<endl;
    cout<<fixed<<setprecision(3)<<area(b1,b2)<<endl;
    cout<<fixed<<setprecision(3)<<area(c1,c2,c3)<<endl;
    return 0;
    }

    #include<iostream>
    #include <iomanip>
    #include <cmath>

    using namespace std;

    int main()
    {
    double a,b,c,d,e,f,t;
    double s1,s2,s3;
    cin>>a>>b>>c>>d>>e>>f;
    s1=a*a;
    s2=b*c;
    t=(d+e+f)/2;
    s3=sqrt(t*(t-d)*(t-e)*(t-f));
    cout<<fixed<<setprecision(3)<<s1<<endl;
    cout<<fixed<<setprecision(3)<<s2<<endl;
    cout<<fixed<<setprecision(3)<<s3<<endl;
    return 0;

    }

  • 相关阅读:
    c++ 单例模式
    c++ 时间格式化
    c++ read
    c++ 时间与字符串转换
    c++ switch case
    HIVE Transform using 用法
    python安装模块
    pip install psutil出错-You are using pip version 10.0.1, however version 18.0 is available.
    centos下安装Loadrunner
    svn-checkout后,循环遍历查找包含某字符串的文件
  • 原文地址:https://www.cnblogs.com/2014acm/p/3911233.html
Copyright © 2011-2022 走看看