bool isPalindrome(int x;
{
if(x < 0 || x>=2147483647)
{ return false;
}else{
int r
esult = 0;
int s = 0;
int temp = x;
while(x != 0)
{ s = x % 10;
result = result * 10 + s; x = x / 10;
}
if((temp == result || temp == 0))
{ return true; }
else{ return false; }
} }
第一個if為什么x要等于它的取值上限,不等于的話就是那個值會導致result overflow溢位,求解惑。
當然定義為long int 型不會溢位。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/115000.html
標籤:C語言
上一篇:求助大佬們
