设有十进制数字a,b,c,d和e,它们满足下列式子:abcd*e=bcde (a不等于0, e不等于0或1),求满足上述条件的所有四位数abcd的和。
无
无
无
正确输出为:3665
#include<iostream>
using namespace std;
int main()
{
int a, b, c, d, e;
int sum = 0; //满足上述条件的所有四位数abcd的和
for (a = 1; a < 10; a++)
for (b = 0; b < 10; b++)
for (c = 0; c < 10; c++)
for (d = 0; d < 10; d++)
for (e = 2; e < 10; e++)
{
{
if (((a * 1000 + b * 100 + c * 10 + d) * e) == (b * 1000 + c * 100 + d * 10 + e))
{
sum += a * 1000 + b * 100 + c * 10 + d;
}
}
}
cout << sum << endl;
return 0;
}
设有十进制数字a,b,c,d和e,它们满足下列式子:abcde=bcde (a不等于0, e不等于0或1),请打印满足上述条件的abcde=bcde,打印格式为abcd*e=bcde,每行一个式子,记得换行。
#include<iostream>
using namespace std;
int main()
{
int a, b, c, d, e;
for (a = 1; a < 10; a++)
for (b = 0; b < 10; b++)
for (c = 0; c < 10; c++)
for (d = 0; d < 10; d++)
for (e = 2; e < 10; e++)
{
{
if (((a * 1000 + b * 100 + c * 10 + d) * e) == (b * 1000 + c * 100 + d * 10 + e))
{
cout << a << b << c << d << "*" << e << "=" << b << c << d << e << "\n";
}
}
}
return 0;
}