问题 - 打印100到500之间的号码。
逻辑错误 -Code未打印任何输出。
使用codeblocks ide编译。
int a,n,i,j,c;
for(j=100;j<=500;j++)
{
int d=0;
n=100;
a=n; //assigning a to n as its value will be changed everytime the loop runs.
for(i=1;i<=3;i++) //loop will run corresponds to 3 digit of the number.
{
c=a%10;
a=a/10;
d=d+c*c*c;
}
// checking if the number = original number
if(d==n)
printf("%d armstrong no\n",d);
//incrementing the number to increase its value after each loop execution
n++;
}
答案 0 :(得分:0)
n=100;
在for循环中,每次,n将= = 100
。它应该在外面循环。