0) Use indentation to show which blocks belong in loops, which else matches which if etc.
Code:
float isNumPalindrome(int x)
{
int pwr=0;
if (x<10) //what about negative values?
return 1;
else
{
while (x/(pow(10.0,pwr)) >=10)
pwr=pwr+1;
while (x>=10)
{
cout << x << ' ' << pwr << '\n'; //you could use debug output, to see what's going on
if (x/pow(10.0,pwr) != (x % 10))
return 0;
else
{
x = x / pow(10.0,pwr);
x = x % 10;
pwr = pwr-2;
}
}
return 1;
}
}
1)
Code:
if (x/pow(10.0,pwr) != (x % 10))
The left-hand side is a floating point value, the right-hand side is integral. E.g the number is 434. You will be comparing 4.34 against 4.0. They will always be unequal.
2)
Code:
else
{
x = x / pow(10.0,pwr);
x = x % 10;
pwr = pwr-2;
}
This section practically destroys the number entirely. E.g input was 146371. Assuming the else branch could be selected at first iteration (as it should), what would be left of x? 1?
What you probably want to do is to chop off the first and the last digit. I suppose subtraction would be useful for the first, e.g 5675 - 5 * 1000 = 675. Dividing by 10 removes the last digit.
--------
The whole thing would probably work out better if you avoided the pow function to keep it entirely to integer arithmetics. You can calculate the power of ten by iteratively multiplying by 10. You can use some_power_of_ten /= 100; instead of pwr = pwr-2;