codescracker


c

C Program to Check Number is Palindrome or Not



« Previous Program Next Program »


Check Palindrome or Not in C

To check for palindrome i.e., whether the input number is palindrome or not in C programming, first reverse the entered number and check whether reverse is equal to its original or not. If, it is equal, then the number is palindrome, otherwise it in not be palindrome number

C Programming Code to Check Number is Palindrome or Not

Following C program ask to the user to enter a number to reverse it, then check whether reverse is equal to its original or not, if it is equal then it will be palindrome else it will not be palindrome:

/* C Program - Check Palindrome or Not */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int num, rem, orig, rev=0;
	printf("Enter a number : ");
	scanf("%d",&num);
	orig=num;
	while(num!=0)
	{
		rem=num%10;
		rev=rev*10 + rem;
		num=num/10;
	}
	if(rev==orig)  // check if original number is equal to its reverse
	{
		printf("Palindrome");
	}
	else
	{
		printf("Not Palindrome");
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result. Above C Programming Example Output (palindrome):

c program check palindrome or not

Above C Programming Example Output (not palindrome):

check palindrome number in c

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test