Friday, July 31, 2009

Write a program in c++ to find string palindrome?

It would be more efficient to just inspect the string and work towards the middle.





1) Create a for loop similar to this one...


i =0; i %26lt; (string.length / 2); i++





2) Inside the loop, compare string[i] to string[string.length - i]


If the values are the same, your string may be a palindrome, continue. If the values aren't the same, it's not a palindrome, break; the loop.





The suggestions above are pseudo-code, but should be helpful. Another thing to keep in mind, is to make sure you convert the characters you are comparing to either be both upper-case or both lower-case. "Racecar" would fail if you don't because the string(or character) "r" does not equal the string "R".





Good luck.

Write a program in c++ to find string palindrome?
Think of the word Racecar. If you spell it backwards it spells Racecar.





Have two variables, One holds the word, the other is the reverse order of the same word. If the two variables are the same then return 1, yes, true, etc. etc.





Use two arrays to store the data and a pointer to read the


array backwards.





There's your hint.





- Hex


No comments:

Post a Comment