C++大学教程(第九版)5.20毕达哥拉斯的三元组

题目

代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int side1, side2, hypotenuse;
    for (side1 = 1; side1 <= 500; side1++)
    {
        for (side2 = side1; side2 <= 500; side2++)
        {
            for (hypotenuse = 1; hypotenuse <= 500; hypotenuse++)
            {
                if (side1 * side1 + side2 * side2 == hypotenuse * hypotenuse)
                    cout << "直角边是:" << side1 << " " << side2 << " 斜边是:" << hypotenuse << endl;
            }
        }
    }
    return 0;
}

运行截图

相关推荐
8Qi812 小时前
LeetCode热题100--45.跳跃游戏 II
java·算法·leetcode·贪心算法·编程
bilI LESS12 小时前
Spring Boot接收参数的19种方式
java·spring boot·后端
web前端进阶者13 小时前
Rust初学知识点快速记忆
开发语言·后端·rust
CheerWWW13 小时前
C++学习笔记——this关键字、对象生命周期(栈作用域)、智能指针、复制与拷贝构造函数
c++·笔记·学习
lucky九年13 小时前
GO语言模拟C++封装,继承,多态
开发语言·c++·golang
九皇叔叔13 小时前
004-SpringSecurity-Demo 拆分环境
java·springboot3·springsecurity
温天仁13 小时前
西门子PLC编程实践教程:工控工程案例学习
开发语言·学习·自动化·php
lsx20240613 小时前
Java 数组
开发语言
JosieBook13 小时前
【C#】VS中的 跨线程调试异常:CrossThreadMessagingException
开发语言·c#
爱滑雪的码农13 小时前
Java八:Character 类与string类
java·开发语言