


运行正常没有编译错误,但是少了5,25等自守数,不知道咋回事,求帮忙
直接看我的代码吧,很好理解的,你的代码有点乱。
思路大概就是:把本来的数和平方之后的数循环对10取余然后进行比较,因为本来的数肯定是小于平方之后的,那么跳出循环的条件就是本身的数取余取成0了。那么在比较过程中如果没有碰到不相等的情况,那么这个数就肯定是自守数了。
这个代码输入一个值,然后求小于这个值的所有自守数。
#include <stdio.h>
typedef long long int llint;
int JudgeAutomorphicNumber(llint number_);
int main() {
llint limit;
scanf("%lld", &limit);
for (llint current = 1; current <= limit; ++current) {
if (JudgeAutomorphicNumber(current)) {
printf("%lld ", current);
}
}
return 0;
}
int JudgeAutomorphicNumber(llint number_) {
llint quadratic = number_ * number_;
while (number_) {
if (number_ % 10 == quadratic % 10) {
number_ = number_ / 10;
quadratic = quadratic / 10;
} else {
return 0;
}
}
return 1;
}