Hi...
This program check numbers that is palindrome or not in reverse order i want to make this program for characters checks palindrome or not like(MOM,MADAM)...
#include<iostream>
usingnamespace std;
main()
{
longint n, num, digit, rev=0;
cout<<" Enter a positive number:";
cin>>num;
n=num;
do
{
digit=num%10;
rev=(rev*10)+digit;
num=num/10;
}
while(num!=0);
cout<<" The reverse of the number is : "<<rev<<endl;
if(n==rev)
cout<<" The number is palindrome";
else
cout<<" The number is not palindrome";
}
just start checking from front and behind till the middle. if any char mismatches then not palindrome. if u reach middle with all char matching then its a palindrome.
First, take a string.
Iterate from its last index to its first index and for every character, append to a new string (just like how you appended to rev using maths but here you do it directly).
Compare both strings. And voila you're done.
Quick mentions:
1) Strings have an operator for +, so you can use += to append to a string.
2) You can use .length() or .size() on a string to get its size.
3) You have to iterate from last index to first index, keep in mind (or you could reserve memory on the second string and use indexes).
4) If you were to use cstrings then do the same but with strlen() instead and you can use strcmp() for comparing (for strings you can just use == operator).