Showing posts with label Palindrome number. Show all posts
Showing posts with label Palindrome number. Show all posts

Wednesday, April 16, 2014

C Program to check the number is palindrome or not

C Program to check the number is palindrome or not
 #include<stdio.h>
#include<conio.h>
void main()
{
int i,temp,sum=0,remainder,number;
clrscr();
printf("Enter the number to check Palindrome: ");
scanf("%d",&number);
temp=number;
while(number>0)
{
remainder=number%10;
number=number/10;
sum=sum*10+remainder;
}
printf("\nreverse of given number is= %d\n",sum);
if(sum==temp)
printf("number is palindrome");
else
printf("number is not palindrome");
getch();
}

Thursday, April 3, 2014

C++ Program to check whether the number is palindrome or not

C++ Program to check whether the number is palindrome or not
A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction.[1] Famous examples include "Amore, Roma", "A man, a plan, a canal: Panama" and "No 'x' in 'Nixon'". --- wiki

#include<iostream.h>
#include<conio.h>
class palindrome
{
int n1,n2,rem,rev;
public:
void input()
{
cout<<"Enter the number\n";
cin>>n1;
}
void calculation()
{
rev=0;
n2=n1;
while (n1>0)
{
rem=n1%10;
n1=n1/10;
rev=rev*10+rem;
}
}
void output()
{
if(n2==rev)
cout<<"Number is palindrome";
else
cout<<"Number is not palindrome";
}
};
void main()
{
clrscr();
palindrome a;
a.input();
a.calculation();
a.output();
getch();
}