Palindrome Number Program in C

A number is said to be palindrome if it satisfy’s a condition,the reverse of the number should be same as the original number.For finding the reverse of the given number we need to get the individual digits of given number as we have done in finding the sum of digits of a given number.I shall explain it again.

To get the last digit of a number, we need to divide the given number with 10 and remainder which we get as a result is the last digit of the number.If the given number is 789 and if we divide the number with 10 we get 9 as remainder and remaining two digits 78 as quotient.If we divide the number 78 by 10 then we get 8 as remainder and 7 as quotient.By dividing 7 by 10 we get 7 as remainder and 0 as quotient.So we have got all the digits of the given number.

By using the same logic in our program we are going to check for palindrome program.In the program we are using the variable n for storing the input,remainder for storing the remainder after each division of number with 10 and reverse for finding the reverse of the number.

#include<stdio.h>
#include<conio.h>
void main()
{
	int n,remainder,rev=0,temp;
	clrscr();
	printf("Enter a number to check whether palindrome or not:");
	scanf("%d",&n);
	temp = n;
	while(temp>0)
	{
		remainder = temp%10;
		temp = temp/10;
		rev=rev*10+remainder;
	}
	printf("Reverse value is :%d",rev);
	if(rev == n)
		printf("\nGiven number %d is palindrome",n);
	else
		printf("Given number %d is not palindrome",n);
	getch();
}

Output:
palindrome
Download the source code

Advertisement

About Anuroop D

Very enthusiastic about technology and likes to share my knowledge through blogging. Has Bachelor's in Information Technology and currently pursuing my PhD in Computer Science.
This entry was posted in C and tagged , , , , , , , , . Bookmark the permalink.

1 Response to Palindrome Number Program in C

  1. Pingback: Palindrome program in Python | Letusprogram

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s