CodePudding user response:
Int cn () function changes for comparison:int cn (int n, m int)
{
Int hun, ten, ind, a, flog=1, z=0;
For (a=n; A<=m; +)
{
Hun=a/100;
Ten=a/10% 10;
Ind=a % 10;
If (a==hun hun hun * * ten plus ten plus ten * * ind ind * * ind)
{
printf("%d ",a);
Z++;
}
}
Flog the if (z==0)=0.
Return the flog;
}
CodePudding user response:
According to the code of the building Lord, should be returned by the return value has a problem, the logic of the building Lord, is in the loop will execute z++, because it is in the for large cycle, always perform to; The possibility of second cn function returns a non-zero? No, because finally return 0; Z just perform a for loop, will perform z++, even for loop does not perform at a time, eventually will return 0; So, non-zero come from where?int CNT (int n, int m)
{
Int the sum, TMP, I;
Int CNT=0;
If (m & gt; N)
Swap (& amp; M, & amp; n);
For (I=m; I & lt; n; I++) {
TMP=I;
sum=0;
While (TMP) {
Rem=TMP % 10;
The sum +=pow (rem, 3);//or rem rem * * rem;
TMP/=10;
}
If (sum==I) {
Printf (" % d is refers to the number! \ n ", I);
cnt++;
}
}
Return CNT.
}
Static int swap (int * a, int * b)
{
Int TMP=* a;
*=* b;
* b=TMP;
}
Reference code, can have a try,