一个回文数与平方数的程序?最近写了个“判断六位数中既是回文数又是平方数的程序”,可老出错,感激不禁!程序如下#include#includeint fun(long *x){long b,c,d,j=0,n,temp1,temp2;temp1=(long)sqrt(100000);temp2=(lo

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 18:40:49

一个回文数与平方数的程序?最近写了个“判断六位数中既是回文数又是平方数的程序”,可老出错,感激不禁!程序如下#include#includeint fun(long *x){long b,c,d,j=0,n,temp1,temp2;temp1=(long)sqrt(100000);temp2=(lo
一个回文数与平方数的程序?
最近写了个“判断六位数中既是回文数又是平方数的程序”,可老出错,感激不禁!程序如下
#include
#include
int fun(long *x)
{
long b,c,d,j=0,n,temp1,temp2;
temp1=(long)sqrt(100000);
temp2=(long)sqrt(999999);
for(n=temp1;n=100000&&n*n0)
{
c=b%10;d=d*10+c;b=b/10;
}
if(d==n*n)
x[j++]=n*n;
}
}
return j;
}
void main()
{
int fun(long *);
long result[50];
int i,num;
num=fun(result);
printf("%d\n",num);
for(i=0;i

一个回文数与平方数的程序?最近写了个“判断六位数中既是回文数又是平方数的程序”,可老出错,感激不禁!程序如下#include#includeint fun(long *x){long b,c,d,j=0,n,temp1,temp2;temp1=(long)sqrt(100000);temp2=(lo
int palindrome(unsigned int x)
{
unsigned int y;
unsigned int s=0;
y=x;
while(y>0)
{
s=s*10+y%10;
y=y/10;
}
if(s==x)
return 1;
else
return 0;
}
void main()
{
printf("符合条件的N为: N平方为:\n");
for(int n=1;n<=200;n++)
{
if(palindrome(n*n))
{
printf(" %-5d %-5d\n",n,n*n);
}
}
}

运行结果如下:
符合条件的N为: N平方为:
1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
Press any key to continue