C语言 等于阶乘和的三位数问题
发布网友
发布时间:2022-04-21 05:54
我来回答
共2个回答
热心网友
时间:2023-10-15 12:08
h,i,j没有每次循环都初始化。
#include<stdio.h>
int main()
{
int a=100,b,c,d,e,f,g,h=1,i=1,j=1;
while(a<=999)
{
h=i=j=1;
b = a/100;
c = a%100/10;
d = a%10;
for (e=1; e<=b; e++)
{
h = h*e;
}
for (f=1; f<=c; f++)
{
i = f*i;
}
for (g=1; g<=d; g++)
{
j = j*g;
}
if (a==h+j+i)
{
printf("%d\n",a);
}
a++;
}
return 0;
}
热心网友
时间:2023-10-15 12:08
//已修改好
#include<stdio.h>
int main()
{
int a=100,b,c,d,e,f,g,h=1,i=1,j=1;
while(a<=999)
{
//要加上这句,重新初始化h、i、j
h=i=j=1;
b = a/100;
c = a%100/10;
d = a%10;
for (e=1;e<=b;e++)
{
h = h*e;
}
for (f=1;f<=c;f++)
{
i = f*i;
}
for (g=1;g<=d;g++)
{
j = j*g;
}
if (a==h+j+i)
{
printf("%d\n",a);
}
a++;
}
return 0;
}