Check given number is Palindrome or not.




                           
                                          First, we see what Palindrome number. If we are giving input as 1254 the program separates each and every integer no and rearrange it in a reverse manner and again see the original number is the same or not, the i.e original number is 1254 and reversed number is 4521, but 1254 is not equal to 4521. Then the output is like 1254 is not a Palindrome number. To see the demo of this code see the following code. 

C language code to check the given number is a palindrome or not:
#include<stdio.h>
#include<conio.h>
void main()
{
    int n, a = 0, r, ori_no;
    clrscr();
    printf("Enter an integer: ");
    scanf("%d", &n);

    ori_no = n;//to store the original number

    while( n!=0 ) //number must be a non zero integer number

    {
       //following formulas to check the given number is palindrome or not
r = n%10;
a = a*10 + r;
n /= 10;
    }

    // palindrome if ori_no and r are equal
    if (ori_no == a)
printf("%d is a palindrome.", ori_no);
    else
printf("%d is not a palindrome.", ori_no);

    getch();
}
-------------------------------------------------------------------------------
output:

Enter an integer:546
546 is not a palindrome.


Enter an integer:45654
45654 is not a palindrome.








Check given number is Palindrome or not. Check given number is Palindrome or not. Reviewed by Amit Waghmare on June 20, 2019 Rating: 5

No comments: