Tuesday, 21 January 2020

To check whether the number is palindrome or not in C++

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,rev=0;
cout<<"enter any number";
cin>>n;
int temp=n;
int sum=0;
while(temp>0)
{
int d=temp%10;
sum=sum+d;
rev=rev*10+d;
temp=temp/10;
}
cout<<"sum of number is"<<sum<<"\n";
cout<<"reverse of number is\n "<<rev<<"\n";
if(rev==n)
cout<<"palindrome\n";
else
cout<<"not palindrome\n";
getch();
}

No comments:

Post a Comment