4 Palindrome Number

9. Palindrome Number

问题:

Determine whether an integer is a palindrome. Do this without extra space.

 

解析:

 

什么是回文数?

答案:“回文”是指正读反读都能读通的句子,它是古今中外都有的一种修辞方式和文字游戏,如“我为人人,人人为我”等。在数学中也有这样一类数字有这样的特征,成为回文数(palindrome number)。设n是一任意自然数。若将n的各位数字反向排列所得自然数n1与n相等,则称n为一回文数。例如,若n=1234321,则称n为一回文数;但若n=1234567,则n不是回文数。

 

判断一个int型数是不是回文数,而且不能用额外空间

 

 

注意:负数没有回文数,因为不知道这个东西,折腾半天。

 

 

#include<stdio.h>

#include < limits.h >

#include < float.h >

 

void main()

{

bool m=false;

int x=0;

bool isPalindrome(int x);

 

 

printf("Please give a data:");

scanf("%d",&x);

m=isPalindrome(x);

 

if(m== true)

printf("The Number is Palindrome Number.");

else

printf("The Number is not Palindrome Number.");

}

 

bool isPalindrome(int x) {

    int reg=0;

int temp = x;

int flag = 0;

 

if (x < 0)

{

return false;

}

 

if(x > INT_MAX || x < INT_MIN)

     {

            x = 0;

     }

 

while(x)

{

reg=reg*10+x%10;

x=x/10;

}

 

if(temp == reg) // 注意这个地方 以前用的X是不对的,因为while循环时候 已经把x进行改变

{

return true;

}

else

{

return false;

}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

狮子座硅农(Leo ICer)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值