zoukankan      html  css  js  c++  java
  • 判断输入三个正整数是否构成直角三角形(是:Yes;不是:No;不构成三角形:Not a trangle)

    #include <iostream>

    using namespace std;
    void judge_triangle(int L, int m, int s); // 若函数调用顺序和函数的编写不一致,需要声明函数
    // 三数排序--从大到小
    void trangle(int x, int y, int z)
    {
    if (x > y)
    {
    if (x > z)
    {
    if (z > y)
    judge_triangle(x, z, y);
    else
    judge_triangle(x, y, z);
    }
    else if (x < z)
    judge_triangle(z, x, y);
    }
    else if (y > z)
    {
    if (y > x)
    {
    if (x > z)
    judge_triangle(y, x, z);
    else
    judge_triangle(y, z, x);
    }
    else if (y < x)
    judge_triangle(x, y, z);
    }
    else if (z > x)
    {
    if (z > y)
    {
    if (y > x)
    judge_triangle(z, y, x);
    else
    judge_triangle(z, x, y);
    }
    else if (z < y)
    judge_triangle(y, z, x);
    }
    }

    void judge_triangle(int L, int m, int s)
    {
    if ((m + s) <= L || (L - m) >= s)
    printf("Not a Triangle ");
    else
    if ((m * m + s * s) == L * L)
    printf("Yes ");
    else
    printf("No ");
    }

    int main()
    {
    int L, m, s;
    while (true) {
    printf("请输入构成三角形的三条边:");
    cin >> L >> m >> s;
    trangle(L, m, s);
    printf(" ");
    }
    return 1;
    }

    在本博客上的内容全部共享公开不收费 转载请注明出处,尊重知识,尊重劳动 对代码或者知识有疑问,可联系博主(qq):2218787597(或邮件投递)
  • 相关阅读:
    浏览器—CORS 通信的学习总结
    前端算法
    移动端适配时对meta name="viewport" content="width=device-width,initial-scale=1.0"的理解
    react和vue的区别
    对xss攻击和csrf攻击的理解
    前端如何解决跨域
    你没那么重要
    五福
    天道
    决策
  • 原文地址:https://www.cnblogs.com/TyranRex/p/12157951.html
Copyright © 2011-2022 走看看