Description:
In this program, either string or number is taken as a input for checking palindrome.
Palindrome
is a specific name given for the word or number which shows the same
name or number when reversed from right to left or vice-versa. While loop is used to check the given condition is palindrome or not. Conslole.WriteLine is used to display the given value is palindrome or not and Console.ReadLine is used to get the input value.
Sample Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace codeforpalindrome
{
class Program
{
static void Main(string[] args)
{
string s1;
int j = 0;
int i = 0;
Console.WriteLine(" Enter the value ");
s1 = Console.ReadLine();
j = s1.Length;
while (i != (j - 1))
{
if (s1[i] == s1[j - 1])
{
i++;
j = j - 1;
}
else
{
Console.WriteLine(" The given value is not a palindrome");
break;
}
}
if (i == (j-1))
{
Console.WriteLine("The given value is a plaindrome");
}
}
}
}
Sample Input_1:
Enter the value:
malayalam
Sample Output: The given value is a palindrome.
Sample Input_2:
Enter the value:
sir
Sample Output: The given value is not a palindrome.
Sample Input_3:
Enter the value:
12321
Sample Output: The given value is a palindrome.
Sample Input_4:
Enter the value:
12345
what if we have toi make make any word a palindrome
ReplyDelete