C语言编程题,求助大神

编写函数int fun(int x) ,其功能是判断整数x是否是同构数。若是同构数,函数返回该数;否则返回0。要求主函数输人n,调用函数fun后输出1~n中的所有同构数(例如,25的平方是625,且25出现在625右侧,则25是一个同构数)。

第1个回答  2020-06-23
楼上的都会不会看题?
#include <stdio.h>

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个回答  2020-06-23
int fun (int x)
{ int xx=x * x;
if(xx==x//xx%10==x//xx%100==x) return 1;
else return 0;
}
第3个回答  2020-06-18
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;

}本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网