作业帮 > 综合 > 作业

c(或++)语言求三元一次方程正整数解的对数

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/28 17:06:41
c(或++)语言求三元一次方程正整数解的对数
比如 5x+3y+z=n x y z都是自然数
输入n 然后输出符合题意的所有解的对数
貌似知道是连用三个循环 但是还是不知道怎么写 求大神代码
c(或++)语言求三元一次方程正整数解的对数
让我来试试,先mark一下
吃完晚饭来整
再问: 然后呢·····
再答: #include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int A(0), B(0), C(0) , D(0);
cout << "please input the number like " << endl;
cout << "A*x + B*y + C*z = D" << endl;
cout << "A = ";
cin >> A ;
cout << "B = ";
cin >> B;
cout << "C = ";
cin >> C;
cout << "D = ";
cin >> D;
cout << "the function you want to do is :" << endl;
cout <<A<<"*x + "<<B<<"*y + "<<C<<"*z = "<<D << endl;
cout << "the solutions are next :" << endl;
for (int i = 0; i < D/A ; ++i)
{
for (int j = 0; j < D/B; ++ j)
{
for (int k = 0; k < D/C ; ++k)
{
if ((i*A + j*B + k*C) == D)
{
cout << "X=" << i << endl;
cout << "Y=" << j << endl;
cout << "Z=" << k << endl;
cout << endl;
}
}
}
}
cout << endl;
system("pause");
return 0;
}
完美解决你的问题,昨晚给忘了,不好意思