C语言编程题,求助大神

2024-11-11 03:57:39
推荐回答(3个)
回答1:

楼上的都会不会看题?
#include

int fun(int x) {
int xx = x * x;
int i = 1;

do {
i *= 10;
if (xx % i == x) {
return x;
}
} while (xx / i);

return 0;
}

int main(int argc, const char* const argv[]) {
int n;

printf("输入n: ");
scanf("%d", &n);

for (int i = 1; i <= n; i++) {
if (fun(i)) {
printf("%d\n", i);
}
}

return 0;
}

回答2:

int fun (int x)
{ int xx=x * x;
if(xx==x//xx%10==x//xx%100==x) return 1;
else return 0;
}

回答3:

int fun(int x) {
int count = 1;

int t = x;

while (t > 0) {

count *= 10;

t /= 10;

}

if (x*x%count==x) {

return x;

}

return 0;

}