Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Write a c program to check a number is palindrome or not:


  • If reverse number of a number is same then we can say its a palindrome number
  • we already know logic to reverse a number using remainder logic
  • read input from the user and store it in a variable
  • check reverse number of given number 
  • compare original number and reverse number if both are same then we can say it's a palindrome number 
  • C Program to Check Whether a Number is Palindrome or Not


Write a c program to check a number is palindrome or not:

  1. #include
  2. int main() {
  3.     int n, revnumber = 0, ramindernum, number;
  4.     printf("Enter number: ");
  5.     scanf("%d", &n);
  6.     number = n;

  7.     // reversed integer is stored in reversedN
  8.     while (n != 0) {
  9.         ramindernum = n % 10;
  10.         revnumber = revnumber * 10 + ramindernum;
  11.         n /= 10;
  12.     }

  13.     //  if number  and revnumber are same then its a palindrome
  14.     if (number == revnumber)
  15.         printf("%d is a palindrome.", number);
  16.     else
  17.         printf("%d is not a palindrome.", number);

  18.     getch();
  19. }


Output:






This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

Write a c program to check a number is palindrome or not:

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×