急~!!用C++写 设abc 是一个三位数,求满足条件abc=a!+b!+c!

2024-12-15 09:51:23
推荐回答(4个)
回答1:

#include
using namespace std;

int main()
{
int fact[11] = {1}, i;
for (i = 1; i <= 10; i ++)
fact[i] = fact[i-1]*i; //求阶乘
int a, b, c;
bool need_to_be_different = false; //每位是否需要不同
for (a = 1; a <= 9; a ++)
for (b = 0; b <= 9; b ++)
for (c = 0; c <= 9; c ++)
{
if (need_to_be_different)
if (a == b || a == c || b == c)
continue;
if (100*a+10*b+c == fact[a]+fact[b]+fact[c])
cout< }
return 0;
}

回答2:

#include

int n(int i)
{
if(i>1)
return i*n(i-1);
else if(i==1)
return i;
}

int main()
{
for(int a = 1;a<=9;a++)
for(int b = 1;b<=9;b++)
for(int c = 1;c<=9;c++)
if(a!=b && b!=c && c!=a && (n(a)+n(b)+n(c)) == (a*100+b*10+c))
std::cout<
return 0;
}

回答3:

呵呵,楼上longinus_dean,C++ 中阶乘不能直接用“!”哦,要计算哦

回答4:

惊叹号是什么意思
不明白
不知是不是
abc=100a+10b+c