C Program : Check for Palindrome Number

0
771

Introducing — Code ! A new and open zone for budding programmers like me and for amateur developers. I believe that writing codes is not a rocket science, it’s fun and interesting. Most people don’t find coding fun because they don’t see the beauty or they find it difficult. But it’s not at all difficult and it’s very much fun, you will soon find it how. In the CODE section I’ll be sharing the programs I created and I’ll also share many things related to CODING.

I was experimenting with C and C++ programming for the last few days and today I’m going to inaugurate the ‘CODE ‘ section with a c programming tutorial. I’ve also learned HTML and CSS but I still have a way to go. I’ll be sharing all the interesting things I’ve learned all the way in my programming life. If you are in need of any program, do post it in our forum or directly contact me and I’ll surely put up the program you requested if I can sort it out. Also, if you have created any interesting programs which can be helpful, you can share them too via the forums or contribute it directly to GeekEngage. I hope my keen readers would surely encourage and support me and drop your valuable feedback 🙂

What is a Palindromic number ?


A palindromic number is a number that remains the same when its digits are reversed.
For example :- 16461 , 121 , 1221 . Here , you see that the number remains the same even after the digits are reversed.

C program for Finding Palindrome Number


In C programming, there are many ways to Check Whether a Number is Palindrome or Not . Here I’ll be using the while loop method to check whether the given number is Palindrome or Not.

Source Code


#include <stdio.h>
#include <conio.h>
void main ()
{
 int a,t,n,r=0;
 clrscr();
   printf(“Enter a number”);
   scanf(“%d”,&n);
t=n;
while(n>0)
 {
a=n%10;
r=r*10+a;
n=n/10;
 }
if (t==r)
 printf(“Palindrome”);
  else
 printf(“Not Palindrome”);
getch();
}

Analysis


 

 Check For Palindrome Number: Output

The basic concept used here is the reversing of numbers. As I said, Palindrome Number is a number that remains the same when its digits are reversed. So, the basic concept applied here is Reversing of Numbers.

There is nothing more to be explained. I just used the ‘while loop’ and if else statements. Moreover, I’ve also stored ‘n’ in ‘t’ since you need to check the number before and after reversing. So we need to store it somewhere and therefore we stored ‘n’ in ‘t’.

So, wasn’t that easy ? Well,  Do share your feedback through comments 🙂