假设有这样一个三位数m,其百位、十位和个位数字分别是a、b、c,如果m= a!+b!+c!,则这个三位数就称为三位阶乘和数(约定0!=1)。请编程计算并输出所有的三位阶乘和数。
函数原型: long Fact(int n);
函数功能:计算n的阶乘
#include <stdio.h>
long Fact(int n)
{
long ret = 1;
for (int i = 1; i <= n; i++)
{
ret *= i;
}
return ret;
}
int main()
{
for (int m = 100; m < 1000; m++)
{
if (m == Fact(m%10)
+ Fact((m/10)%10)
+ Fact(m/100))
{
printf("%d\n",m);
}
}
return 0;
}