首先设计界面
编写如下代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace zh
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int zh =Convert .ToInt32( textBox1.Text);
int t=(int)Math.Sqrt (zh);
int i;
for (i = 2; i <=t;i++ )
{
if(zh % i==0)
{
break;
}
}
if (i <= t)
{
label2.Text = zh+"不是质数";
}
else
{
label2.Text = zh+"是质数";
}
textBox1.Text = "";
}
}
}
运行结果