Showing posts with label palindrome. Show all posts
Showing posts with label palindrome. Show all posts

Wednesday, May 16, 2018

C program to check whether the given number is palindrome.

Program code
#include <stdio.h>
#include <conio.h>
void main()
{
long int temp=0, number=0, reverse=0;
clrscr();
printf(“Please input a whole number to find out whether it is a palindrome.\n”);
scanf(“%ld”,&number);
for (temp=number;temp>0;temp=temp/10)
reverse=(reverse*10)+(temp%10);
if (number==reverse)
printf(“%ld is palindrome.\n”,number);
else
printf(“%ld is not a palindrome.\n”,number);
getch();
}

Example of output
Please input a whole number to find out whether it is a palindrome.
1221
1221 is palindrome.