Hello guyz, can someone teach me how to make a palindrome?
I am thinking that first i should store it in my array, then we should get the length of a string.
Then After divide it by two and compare the first and last character of the word.
Can someone help me how to code this thing?
Thanks, I'll be waiting for your help. =)
You will have to account for ignored characters and case differences also. Before reversing, convert everything to uppercase or lowercase, and remove all characters that don't count.
#include <fstream>
#include <iostream>
#include <cstring>
usingnamespace std;
int main()
{
char wordenter[30];
int length;
cout<<"Enter a word\n";
cin>>wordenter;
cin.get();
length = strlen(wordenter);
cout<<"You enter the word "<<wordenter<<" with the length of "<<length<<endl;
cin.get();
int i, j, palindrome;
for (i=0, j=length-1, palindrome=1; j>i; j--, i++)
{
if(toupper(wordenter[i]) != toupper(wordenter[j]))
{
palindrome = 0;
break;
}
}
cout<<"Word "<<wordenter<<(palindrome?"is":"is not")<<" a palindrome."<<endl;
cin.get();
return 0;
}
#include <iostream>
#include <fstream>
#include <cstring>
usingnamespace std;
int main(void){
bool palindrome=true;
char word[30];
cout << "Please input a word and press return" << endl;
cin>>word;
int length = strlen(word);
cin.get();
cout << "The word has " << length << " characters" << endl;
int char_checks=int(length/2);
cout << char_checks << " characters need to be checked" << endl;
if (length>0){
for(int i=0;i<(char_checks);i++)
{
cout << "checking " << word[i] << " against " << word[length-1-i] << endl;
if(word[i]!=word[length-1-i])
palindrome=false;
}
}
if(palindrome==true)
{
cout << "The word is a palindrome" << endl;
}
else
{
cout << "The word is not a palindrome" << endl;
}
cin.get();
return 0;
}