Write a program using string function that determines if the input word is a palindrome. A palindrome is a word that produces the same word when it is reversed. Sample input/output dialogue: Enter a word: AMA Reversed: AMA “It is a palindrome” Enter a word: STI Reversed: ITS “It is not a palindrome”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q179085
{
class Program
{
static void Main(string[] args){
string word,reversedWord="";
//Get the word
Console.Write("Enter a word: ");
word = Console.ReadLine();
//reverse the word
for (int i = word.Length - 1; i >= 0; i--) {
reversedWord+=word[i];
}
//display reversed word
Console.WriteLine("Reversed: {0}", reversedWord);
//check if word is palindrome
if (word.CompareTo(reversedWord) == 0)
{
Console.WriteLine("It is a palindrome");
}
else {
Console.WriteLine("It is not a palindrome");
}
Console.ReadLine();
}
}
}
Comments
Leave a comment