Write a program that find palindromes. The GUI of program is given to you.
Input words in first text-box and the palindromes should be printed in second
text-box by pressing the button.
Input words in first text-box and the palindromes should be printed in second
text-box by pressing the button.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Palindrome
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonClear_Click(object sender, EventArgs e)
{
}
private void buttonGenerate_Click(object sender, EventArgs e)
{
string rtb;
string palin="";
string tempString,tempString2,testString="";
//char[] temp;
//int i = 0;
rtb = words.Text+"\n";
foreach (char c in rtb)
{
testString += Convert.ToString(c);
if (c == '\n')
{
char[] temp = palin.ToCharArray();
tempString2 = new string(temp);
Array.Reverse(temp);
tempString = new string(temp);
if (tempString == tempString2)
{
tempString += "\n";
palindrome.Text += tempString;
}
else
{
palindrome.Text += "\n";
}
palin = "";
}
else if (c != '\n')
{
palin += Convert.ToString(c);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
words.Clear();
palindrome.Clear();
}
}
}
Post A Comment:
0 comments: