// isPalindrome.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
bool isPalindrome(int N)
{
int M = N;
int remain = 0;
int revertNum = 0;
while (M != 0)
{
remain = M%10;
M = M/10;
revertNum = revertNum*10 + remain;
}
if (abs(revertNum) == abs(N))
return true;
else
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
if (isPalindrome(-123))
printf("true\n");
if (isPalindrome(-12321))
printf("true\n");
if (isPalindrome(123454321))
printf("true\n");
if (isPalindrome(12345421))
printf("true\n");
return 0;
}
判断一个整型数是否是回文的形式
最新推荐文章于 2021-12-22 15:39:48 发布