palindrom checker

This is a discussion on palindrom checker within the C Programming forums, part of the General Programming Boards category; i need to write a function that inputs a number and tells if its palindrom or not i wrote a ...

1. palindrom checker 12

i need to write a function that inputs a number and tells if its palindrom or not
i wrote a code which calculates the length of the number and gets each cycle the digit

how to continue
?
Code:
```#include <stdio.h>
int palindrom(int num);
int main()
{
int t;
t=palindrom(541);
return 0;
}

int palindrom(int num)
{
int digit;
int ans=0;
int cnum,len=0;//length of the number
//calculating the length of the array
cnum=num;
while (cnum/10)
{
digit=cnum%10;
len++;
cnum=cnum/10;
}
len++;
return ans;
}```

2. I don't see the algorithm to solve the problem, though. It's OK code, but no good for the purpose. I mean, you COULD peel off each digit, put it into a string, and then check if it's a palindrome, but why do that?

Do you have itoa() on your system? if so, I'd use it to put the number into a string, and then check it using either a pair of pointers (left and right ends, coming together in the middle), or use the (imo easier to understand for beginners especially), the high and low index numbers, and bring them together toward the middle of the string, until they cross.

If they meet, and a[left++] == a[right--], all the way through the string, then it's a palindrome.

IMO, you need to work toward an algorithm first, and work on the details of the code, later. I'm used to working out programs solo, so that might very well just be my bias.