Answer to Question #179085 in C# for Patrick Ian Kyle Mabunay

Question #179085

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”


1
Expert's answer
2021-04-07T08:53:49-0400
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();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS