C Program to check whether number is palindrome or not
Write a C program to enter any number and check whether given number is palindrome or not using for loop. How to check whether a number is palindrome or not in C programming. C program for palindrome numbers.
Palindrome numbers
If a number remains same, even if we reverse its digits then the number is known as palindrome number. For example 12321 is a palindrome number because it remains same if we reverse its digits.
Algorithm
-
Get the number from user.
-
Reverse it.
-
Compare it with the number entered by the user.
-
If both are same then print palindrome number
-
Else print not a palindrome number.
For Example:
Enter a number: 121
Output: 121 is Palindrome
Here is source code of the C program to checks whether number is palindrome or not. The C program is successfully compiled and run on a Windows system. The program output is also shown below.
SOURCE CODE : :
#include<stdio.h> #include<math.h> int main() { long int n, num, rev = 0, dig; printf("\n\nENTER A NUMBER----: "); scanf("%ld", &num); n = num; while(num>0) { dig = num % 10; rev = rev * 10 + dig; num = num / 10; } if (n == rev) printf("\nGIVEN NUMBER IS A PALINDROME"); else printf("\nGIVEN NUMBER IS NOT A PALINDROME"); return 0; }
OUTPUT : :
ENTER A NUMBER----: 141 GIVEN NUMBER IS A PALINDROME