# code to reverse a 4=digit number+finding if 4 digit number is a palindrome

• 10-31-2009
code to reverse a 4=digit number+finding if 4 digit number is a palindrome
Hi everyone,
Just started learning C.I worked on the first part and wrote a code that finds the reverse of the 4 digit number.But i am unsure as to what to do about the palindrome thing.I have to use only if-else statements.Please help me out with this one.Thanks!!
Code:

```# include<stdio.h> int main() {       int n;       printf("Enter a four-digit number:");       scanf("%d",&n);             printf("The reversed four digit number is %d,%d,%d,%d \n",(n%10),(n/10)%10,(n/100)%10,n/1000);       return (0); }```
• 10-31-2009
Subsonics
You have the first part. Now store the last two numbers like you did the reversal in the printf statement in a variable, then store the first two. If they are equal you have a palindrome.
• 10-31-2009
DoctorBinary
Just reverse the number and compare it to itself. You can do that using strings, or more elegantly using integers.

In my article "Finding Numbers That Are Palindromic In Multiple Bases", I have a C function called isPalindrome that does the check using integers (it uses a while loop though).