Write a C Program to check whether number is palindrome or not

By | 10.10.2016

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

  1.  Get the number from user.

  2. Reverse it.

  3. Compare it with the number entered by the user.

  4. If both are same then print palindrome number

  5. 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

 

3.9 8 votes
Article Rating
Category: C Programming Number Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments