This is the simple but trick programming exercise. The program will identify that is the string is palindrome or not. The palindrome is that which looks same from both sides e.g ACCA , DBBD.
Source Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace pakindromeCS
{
class Program
{
static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Hello, world!");
String userEntered, palindrome = "";
Console.WriteLine("Enter some text to check palindrome");
userEntered = Console.ReadLine();
int stringSize = userEntered.Length;
for (int i = stringSize - 1; i >= 0; i--)
palindrome = palindrome + userEntered[i];
Console.WriteLine((userEntered == palindrome ? "palindrome." : "not a palindrome."));
userEntered = Console.ReadLine();
}
}
}
0 comments:
Post a Comment