6.3.
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 C_SHARP
{
class Program
{
static void Main(string[] args)
{
string word;
//Get the word
Console.Write("Enter a word: ");
word = Console.ReadLine();
string reversedWord = new string(word.Reverse().ToArray());
//display reversed word
Console.Write("Reversed: {0}", reversedWord);
//check if word is palindrome
if (word == reversedWord)
{
Console.WriteLine(" \"It is a palindrome\"");
}
else
{
Console.WriteLine(" \"It is not a palindrome\"");
}
Console.ReadKey();
}
}
}
Comments
Leave a comment