Palindrome Number in C


Q. Write a C program to check Palindrome Number or Not.

#include <stdio.h>
 
void main()
{
   int n, sum = 0, t;
   printf("Enter the number: ");
   scanf("%d", &n);
   t = n;
   while (t > 0)
   {
      sum = sum * 10 + t%10;
      t = t/10;
   }
   if (n == sum)
   {
      printf("%d is a palindrome number.", n);
   }
   else
   {
      printf("%d is not a palindrome number.", n);
   }
}

Q. Write a C program to check Palindrome Number or Not.

1. Start
2. Input the integer number `n`
3. Initialize an integer variable `sum` to 0.
    This will store the reversed number.
4. Initialize an integer variable `t` and assign the value of `n` to it.
    `t = n`
5. While `t` is greater than 0, repeat steps 6 to 8:
6. Get the last digit of the number `t` by using modulo operation:
    `digit = t % 10`
7. Append the digit to `sum` by shifting previous digits to the left:
    `sum = sum * 10 + digit`
8. Remove the last digit from `t` by using integer division:
    `t = t / 10`
9. Compare the original number `n` with the reversed number stored in `sum`
- If `n` is equal to `sum`, then `n` is a palindrome number.
- Else, `n` is not a palindrome number.
10. Print the result accordingly.
11. End



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.