English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i need this program for a assignment

2006-12-12 14:38:55 · 2 answers · asked by GC 1 in Education & Reference Homework Help

2 answers

Set up a for loop starting at the length of the string and moving backward one character at a time until you reach the first character.

Inside the loop copy the character you are at to the end of a new string which you dimensioned the same size as the original .

When you reach the end of the first string all of the characters should be copied in reverse order to the second string.

Now just compare your original string to the new string if they are equal then the original sting was a palindrome.

2006-12-12 14:45:19 · answer #1 · answered by aiguyaiguy 4 · 1 0

This should not be too bad. I don't know c++ at all, but you should be able to loop on the number of letters in the string. Here is some pseudo-code

if (n is odd) // n is the length of the string
{lengthToCheck = (n-1)/2}
else
{lengthToCheck = n/2}
endif

palindrome = true
for i= 1 to lengthToCheck
{if(i-th element in string <> n+1-i-th element in string) then
{palindrome = false
exit(false)
}
}

That should do it. Hope this is helpful from someone who knows very little C++ code.

2006-12-12 14:45:40 · answer #2 · answered by firefly 6 · 0 0

fedest.com, questions and answers