查找毕达哥拉斯三元组,总和为 1000,没有错误但不运行

Finding pythagorian triplets, with sum 1000, no error but doesnt runs

本文关键字:有错误 1000 运行 毕达哥拉斯 三元组 查找      更新时间:2023-10-16

这是代码

#include <iostream>
#include <cmath>
int main()
{
    float c, d;
    for(int a = 1; a < 1000; ++a) {
        for(int b = 1; b < 1000; ++b) {
            c = (a*a) + (b*b);
            c = sqrt(c);
            d = a + b + c;
            if(d==1000) {
                std::cout << a << "," << b << "," << c << std::endl;
                break;
            }
        }
    }
    system("pause");
    return 0;
}

无法在我的系统 Dev-C++ 4.9.9.0 上运行它。

但是当在在线编译器中尝试它时,它给出了输出,但具有以下输出:

200,375,425
375,200,425
Disallowed system call: SYS_fork
我想在线

编译器不允许调用

system("pause");

因为这会创建一个新过程。尝试删除该行,看看它是否运行得更好!

在程序结束时暂停的另一种方法是在顶部包含iostream,然后在最后等待输入,然后再返回:

//At the top
#include <iostream>
// Before return 0;
std::cin.get();