How to Write a Palindrome Programme using C# ?
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{ static void Main(string[] args) {
string str=string .Empty ;
Console.WriteLine("Enter a String");
string s = Console.ReadLine();
int i = s.Length;
//we can get the Length of string by using Length Property
for (int j=i -1; j >= 0; j--)
{
str = str + s[j ];
}
if (str == s)
{
Console.WriteLine(s + " is palindrome");
}
else
{
Console.WriteLine(s + " is not a palindeome"); }
Console.WriteLine(str);
Console.Read();
}
} }
OutPut: Enter a String
MadaM
Madam is palindrome
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{ static void Main(string[] args) {
string str=string .Empty ;
Console.WriteLine("Enter a String");
string s = Console.ReadLine();
int i = s.Length;
//we can get the Length of string by using Length Property
for (int j=i -1; j >= 0; j--)
{
str = str + s[j ];
}
if (str == s)
{
Console.WriteLine(s + " is palindrome");
}
else
{
Console.WriteLine(s + " is not a palindeome"); }
Console.WriteLine(str);
Console.Read();
}
} }
OutPut: Enter a String
MadaM
Madam is palindrome
0 comments:
Post a Comment