string[] words = {"racecar" ,"talented", "deified", "tent", "tenet"};
Console.WriteLine("Is it a palindrome?");
foreach (string word in words)
{
Console.WriteLine($"{word}: {IsPalindrome(word)}");
}
bool IsPalindrome(string word)
{
int startPointerIndex = 0;
int endPointerIndex = word.Length - 1;
for (int i = 0; i < word.Length - 1; i++)
{
if (word[startPointerIndex] == word[endPointerIndex] && startPointerIndex < endPointerIndex)
{
continue;
}
else
{
return false;
}
startPointerIndex++;
endPointerIndex--;
}
return true;
}
string[] words = {"racecar" ,"talented", "deified", "tent", "tenet"};
Console.WriteLine("Is it a palindrome?");
foreach (string word in words)
{
Console.WriteLine($"{word}: {IsPalindrome(word)}");
}
bool IsPalindrome(string word)
{
int startPointerIndex = 0;
int endPointerIndex = word.Length - 1;
for (int i = 0; i < word.Length - 1; i++)
{
if (word[startPointerIndex] == word[endPointerIndex] && startPointerIndex < endPointerIndex)
{
continue;
}
else
{
return false;
}
startPointerIndex++;
endPointerIndex--;
}
return true;
}