• # Program to find whether given number is palindrome using C.

Studying for C programming exam? Searching for solution to finding if a number is a palindrome or not? On this Ask Expert page you can check out responses from experts to your question and decide how to proceed with exam preparation.

Question paper of Diploma in Computer Engineering (affiliated by MSBTE, Mumbai) for Summer 2018 contain the following question. This question carry 4 marks. It is expected that some explanation about the question is given. This question is asked in question paper of PIC(Programming in C) of I scheme with subject code 22226. So waiting for a solution to the asked question in C language only.
Q) Develop a program to accept an integer number and print whether it is palindrome or not.
[ 4 Marks]

• Palindrome number is the number who's reverse number when obtained is same as that of the original number. It means if we read a number in forward or reverse direction then it appears the same. If we consider 121 is the input to the program then
121
now 1*100=100
now 121/10=12
now 2*10=20
now 100+20=120
now 12/10=1
now 120+1=121

So 121 is a palindrome number.

Let us check it with number 152.

now 2*100=200
now 152/10=15
now 5*10=50
now 200+50=250
now 15/10=1
now 250+1=251
So 152 and resultant 251 are not equal numbers. Hence 152 is not a palindrome number.

Following is the program to check whether given number is palindrome or not.
Please include stdio.h and conio.h header files before declaration of main function.

//PROGRAM TO FIND WHETHER GIVEN NUMBER IS PALINDROME OR NOT.
#include
#include
void main(void)
{
int m,num,s=0,r;
clrscr();
printf("Enter any integer number\n");
scanf("%d",&num);
m=num;
for(num=num;num>0;num=num/10)
{
r=num%10;
s=(s*10)+r;
}
if(m==s)
{
printf("\n%d is a palindrome number",m);
}
else
{
printf("\n%d is not a palindrome number",m);
}
getch();
}
In the above program if we consider inputted number is 252. Then firstly we get 2 as result of num%10. Then we multiply s by 10 and add value of r with s. Note that basically value of s is zero, so in first iteration value of s become 2. Mean while by using statement num=num/10 we get value of num as 25 which is greater than zero and hence above mentioned process is repeated untill value of num becomes zero.
Initially after receiving the value for num by user we store that value in a variable m. So after completion of looping we compare value of s with value of m and if they are equal then our number palindrome other wise our number is not palindrome.

• The reverse of a given number is equal to the same number. If you take n vlaue is a 121 just consider. If you reverse this number the value is a same 121. Such type of numbers are called palindrome numbers. Below is a program to check whether the number is palindrome or not in c programming :
First include header file after #include between less than and greater than sign standard I/O and console I/O

#include
#include
void main()
{
int a, num, i=0, result=0, n;
Printf("Enter the number");
Scanf("" %d", & n) ;
num=n;
while(num! =0)
{
result=result*10
a[i]=num%10;
num=num10;
result=result+a[i];
i++;
}
if(result==n)
Printf("The number is palindrome");
getch();
}

Output :
Enter the number
5225
The number is palindrome