C program to check whether a given number is Palindrome or Not - Palindrome program in C

 

How to check a number is palindrome or not

What is a Palindrome Number?

A positive integer is said to be a  palindrome number or, shortly, a palindrome if its leftmost digit is the same as its rightmost digit, its second digit from the left is equal to its second digit from the right, and so on. For example, 33, 142505241, and 6 are palindrome numbers. When we read these numbers from front and end,  it will be the same.

    1. #include<stdio.h>
    2. int main()
    3. {
    4.     int num;
    5.     int r;
    6.     int sum=0;
    7.     int temp;
    8.               printf("Enter number to check palindrome or not\n");
    9.               scanf("%d",&num);
    10.               temp = num;
    11.     while(num>0)
    12.                        {
    13.                          r = num%10;
    14.                          sum = (sum*10)+r;
    15.                          num = num/10;
    16.                         }
    17.     if(temp == sum)
    18.     printf("Number is palindrome \n");
    19.     else
    20.     printf("Number is NOT palindrome\n");
    21.     return 0;
    22. }

Post a Comment

0 Comments