A palindrome is a number or a text phrase that reads the same backwards as forwards. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write a program that reads in a five-digit integer and determines whether it is a palindrome. [Hint: Use the division and modulus operators to separate the number into its individual digits.] Note: Although this exercise talks about a five digit number, think about any length for the number.
im not sure whats the method required here, im guessing it has to be divided by 10 or something, but how do you apply that on C#.
Thanks!
Loading
VulpesPosted Feb 22, 2012, 5:48 AM
Shaker AlSalemPosted Feb 22, 2012, 11:47 PM
FroglegPosted Feb 22, 2012, 5:01 AM
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string ss = textBox1.Text;
string str = ReverseString(ss);
if (str == ss)
{
MessageBox.Show("Palindrone");
}
else
{
MessageBox.Show("Not a Palindrone");
}
}
public string ReverseString(string s)
{
char[] arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
}