
The only logic it tasks is reversing the number that we want to check for palindrome. Printf("%d is not a palindrome number",num) Ĭhecking a palindrome number in C is very easy. If the number match, we will print the number is a palindrome if not we print its not a palindrome number. Then using a while loop we will try to reverse the entered number using % and other athematic operationĪt last, we will compare the reversed number with the entered number A palindrome number is one that remains the same on reversal. By default, all the 1-digit numbers are palindrome numbers.įirst, we will ask the user to enter a number For example, 16461 is a palindrome number if you reverse this number still, we get 16461. let's discuss the Palindrome Program in C.Ī palindrome number is a special number because it remains the same when its digit gets reversed. If the last digit is equal to the first digit then the number is palindrome, otherwise not.Here in this program, we will code to check whether an entered number is a palindrome number or not.

And the variable c holds the first digit of the number. The variable b holds the middle digit of the three digit number. The statement a=a/10 removes the last digit. Here, variable x holds the last digit of the number. The statement num=num/10 again removes the last digit and the loop continues as long as n>0. Then the value currently being stored at res is multiplied by 10 and c is added to res. On the second loop, c again stores the last digit of the number. Then the statement num=num / 10 removes the last digit of the digit as for example, 129/10 equals to 12. The variable res is initially 0 so res*10 = 0 + c which is equal to res=c. When num>0 the c variable stores the last digit of the number. The loop begins and continues to loop as along as num>0.

Another variable chk is assigned the same value as num to check the result at the end of the program. The entered number is assigned to variable num. Here the user is asked to enter a number. For example 12321 is a palindrome number because it. Printf ("n The entered number is NOT PALINDROME.") If a number remains same, even if we reverse its digits then the number is known as palindrome number. Printf("n The entered number is PALINDROME.") Example 1: Check Palindrome Using while Loop and if…else Statement C program to check whether the number is palindrome or not is shown below.

Some examples of palindrome number are: 121, 12321, 515, etc. A palindrome number is a number whose reverse is the original number.
