Palindrome Number?
A palindromic number or palindrome number is a number that remains the same when its digits are reversed. Like 16461.Logic For Palindrome:
When the reverse of a number is equal to the number itself than its a palindrome. So we just need to reverse the number and than check whether it matches to the entered number or not and print the output saying whether the number is palindrome or not.
Source Code:
#include <stdio.h> #include <conio.h> //Reversing the number int reverse(int num){ int rev = 0; while(num>0){ rev = rev*10 + num%10; num = num/10; } return rev; } void main(){ int n; printf("Enter a number: "); scanf("%d",&n); if(n == reverse(n)){ printf("Number is Palindrome!"); } else{ printf("Number is not a Palindrome!"); } getch(); }
Output:
3 Comments Leave new
Nice. I like it. It will not wait for the screen to show result as it doesn't wait for user key input after the result is calculated. Include conio header file as well.
ReplyWhy the syntax in blockquote is so messed and weird?
I am using Code::Blocks IDE and it doesn't required getch() that's why i skipped the conio header file :)
ReplyIts Syntax Highlighter 3.08 and there's some bugs in it... thanks for sharing i will correct it soon!
Nice post ... ! Keep up mark :-)
ReplyMake sure you tick the "Notify Me" box below the comment form to be notified of follow up comments and replies.