What is palindrome number in C?

1 min 33 sec Basic


In this article, we are going to cover the following points

  1. What is Palindrome number in C?
  2. Algorithm of Palindrome number
  3. Implementation of Palindrome Program

Palindrome numbers are referred to as those numbers which give the same number after reversing that number.

For example: Suppose a given number is 1551, then the palindrome number of the given number will be 1551.

2) Palindrome number of 343 will be 343.

Algorithm for Palindrome number in C

Lets write the basic algorithm to check whether the given number is palindrome or not.

  1. Get the number as input from the user.
  2. Hold the given number in a new temporary variable.
  3. Reverse the given number.
  4. Compare the temporary number with a reversed number.
  5. If both the temporary number and reverse numbers are the same, then the given number will be palindrome else number is not a palindrome.

Implementation of Algorithm

Write a program to reverse a number and check whether a given number is palindrome or not.

#include
 int main() 
 {
int i=1551,j;
j = i;
int n,rem,quo,newnumber=0;
for(n=1;n<=4;n++)
{

rem=i%10;

if(n == 4)
{                    
newnumber=(newnumber+rem);
}
else
{
newnumber=(newnumber+rem)*10;
}
quo=i/10;
i=quo;


}

printf("
New number = %d",newnumber);
printf("
Old number = %d",j);


if(j == newnumber)
{
   printf("
Palindrome");
}
else
{
   printf("
Not Palindrome");

}
}

Output

New number = 1551
Old number = 1551
Palindrome

How was the tutorial? Nice. Right?



Deep Concept videos to crack the highly-piad interviews.

Chekout out our Youtube Channel to get detailed video content on important topics in interviews.



What is your Interview Score?

Test your skillset with the curated questions created by experts around the globe.

Book a free test slot. Now !.

It usually takes 30 mins for an online test and this test will be MCQ based. Get detailed analytics based on your test and recommedations with personalised roadmaps.

Book a test slot. Now!

Have questions about the trial coding class?

Chat with our experts to discuss

Connect on WhatsApp


Recommended tutorials

#online compiler for c     #python for programming    

#dfs and bfs algorithm     #programming with c language

#storageclass in C    #listcomprehension in python