欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

c语言回文数递归,c语言问题~~~回文数!!急,拜托高人指点!!

发布时间:2023/12/2 54 豆豆
生活随笔 收集整理的这篇文章主要介绍了 c语言回文数递归,c语言问题~~~回文数!!急,拜托高人指点!! 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

满意答案

wyhjjq1

2014.01.27

采纳率:53%    等级:12

已帮助:10413人

添加上满足你补充要求的C程序:

#include

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");

for(int n=1;n<=200;n++)

{

if(palindrome(n*n))

{

printf(" %-5d\n",n);

}

}

}

运行结果如下:

符合条件的N为:

1

2

3

11

22

26

101

111

121

Press any key to continue

已经上机验证过了!!!

#include

#include

#include

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 Reverse(unsigned char *buf,int size)

{

int i;

unsigned char temp;

if (buf==NULL || size<2) return;

for (i=0;i

{

temp=buf[i];

buf[i]=buf[size-i-1];

buf[size-i-1]=temp;

}

}

void main()

{

int count=0;

unsigned int x,temp;

char strt[10];

cout<

cin>>x;

if(palindrome(x)&&x<2147483647)

{

cout<

return;

}

int i=1,itmp;//

while(x<2147483647)//2147483647)

{

i=1;

itmp=pow(10,i);

while(x/itmp)

{

i++;

itmp=pow(10,i);

}

itoa(x,strt,10);

Reverse((unsigned char*)strt,i);

temp=atoi(strt);

x+=temp;

if(palindrome(x))

{

cout<

return;

}

}

cout<

}

00分享举报

总结

以上是生活随笔为你收集整理的c语言回文数递归,c语言问题~~~回文数!!急,拜托高人指点!!的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。