This is the program to check for the ‘Palindrome’ property of the given number. Palindrome is the instinct property of any literal segment, where the segment reads the same either from left to right or vice versa.
For example : 12321 and LEVEL are the palindromes as they reads same if we go from right to left also.
Logic : The program expects the user to enter the number to check if palindrome. The entered number is reversed and stored in another variable. Finally the reversed number is checked for equality with the entered number. If they are the same, then it is a palindrome.
A slight change in the code can check if the entered string is a palindrome.
#include<stdio.h>
#include<math.h>
void main()
{
long int n, num, rev = 0, dig;
clrscr();
printf(“nnt ENTER A NUMBER…: “);
scanf(“%ld”, &num);
n = num;
while(num>0)
{
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}
if (n == rev)
printf(“nt GIVEN NUMBER IS A PALINDROME”);
else
printf(“nt GIVEN NUMBER NOT A PALINDROME”);
getch();
}
Download exe and source code here.
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
there is no need for including “math.h” rather than you should have included “conio.h” cause getch(); wont work without it, but the idea of reversing the number is amazing
In this pgm why the entered no. is stored as temporory
c++ program to check the given number is a palindrome or not
please send the 100% correct program