C++编程题目,求高手
求方程3*x-2*y=50,在|x|<40,|y|<30条件下的解的个数?
追问:不错
求方程3*x-2*y=50,在|x|<40,|y|<30条件下的解的个数?
追问:不错
答案:代码:
#include <iostream>
using namespace std;int main()
{
int x=0,y=0;
for(x=-39;x<40;x++)
for(y=-29;y<30;y++)
{
if(50==(3*x-2*y))
{
cout<<"x:"<<x<<endl<<"y:"<<y<<endl;
}
}return 0;
}
【酷_酷_币】为您服务...
#include <iostream>
using namespace std;int main()
{
int x,y,cnt=0;
for(x=-39;x<=39;x++)
{
for(y=-29;y<=29;y++)
{
if(3*x-2*y==50)
{
cout << "x = " << x << ", y = " << y << endl;
cnt++;
}
}
}
cout << "count = " << cnt << endl;
return 0;
}
上一个:c++编程题 类与对象
下一个:c++编程,关于数组的