C++ 如何求和正积的负因子
我可能没有在标题中很好地解释这一点,因为我真的不知道如何解释标题的长度,所以我对此表示歉意。无论如何,这是我当前的代码:C++ 如何求和正积的负因子,c++,C++,我可能没有在标题中很好地解释这一点,因为我真的不知道如何解释标题的长度,所以我对此表示歉意。无论如何,这是我当前的代码: // Gets the product that is used to get the factors cout << "Enter a number that you want to be factored" << endl; cin >> y; system("cls"); // Gets the sum from the user
// Gets the product that is used to get the factors
cout << "Enter a number that you want to be factored" << endl;
cin >> y;
system("cls");
// Gets the sum from the user that the two factors need to add up to
cout << "Input the sum that is needed" << endl;
cin >> neededSum;
secondary = y;
system("cls");
// Lists the factors that add up to the specified sum
cout << "The numbers that add up to " << neededSum << " are:" << endl;
for (int i = 0; i < 100; i++)
{
x++;
increment++;
y = secondary / x;
product = x * y;
if (product == secondary)
{
sum = x + y;
if (sum == neededSum)
{
cout << x << " and " << y << endl;
}
}
}
//获取用于获取因子的产品
库蒂;
系统(“cls”);
//从用户处获取两个因子的总和
不需要总和;
次级=y;
系统(“cls”);
//列出加起来等于指定总和的因子
不能假设x和y为负:
if (product == secondary)
{
sum = x + y;
if (sum == neededSum)
{
cout << x << " and " << y << endl;
}
else if (-sum == neededSum)
{
cout << -x << " and " << -y << endl;
}
}
if(产品==次级)
{
总和=x+y;
如果(总和==需要总和)
{
一开始就把它们都写出来怎么样?那么所有的底片和帖子呢?