To check whether the number is palindrome or not

To check whether the number is palindrome or not

Question:

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

Logic:

  • Get the input number from the user.
  • Then reverse the given number using any algorithm.
  • And compare the given number with reversed number.
  • Print the output as palindrome or not.

Algorithm:

  1. Get the input value from the user.
  2. Find the last digit of the number.
  3. Then reverse the number using some calculation.
  4. Removes the last digit by dividing the number with 10.
  5. Repeat step 2 to 4 until it ends.
  6. Then print the valid output.

Program:

#include<stdio.h>
#include<math.h>
void main()
{
	int a,r,sum=0,b;
	clrscr();
	printf("enter the number:");
	scanf("%d",&a);
	b=a;
	while(a>0)                     //reverse the number
	{
		r=a%10;                    //finds the last digit
		sum=r+sum*10;              //reversing number
		a=a/10;                    //removes the last digit
	}
	if(b==sum)                     //compare the given number with reversed number
	{
		printf("Given number is palindrome:");
	}
	else
	{
		printf("Given number is not palindrome:");
	}
	getch();
}

You might also like:

To print all palindromes in a word

 

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Vignesh

A Computer Science graduate who likes to make things simpler. When he’s not working, you can find him surfing the web, learning facts, tricks and life hacks. He also enjoys movies in his leisure time.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x