form1.cs
来自「Visual C#2005程序设计教程」· CS 代码 · 共 43 行
CS
43 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinAppTest5_1筛选素数
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (txtNum.Text == "")
{
MessageBox.Show("请输入一个正整数", "提示",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
return;
}
int n = int.Parse(txtNum.Text);
int a = 1;
for(int i=3;i<=n;i++)
{
a = 1;
for(int j = 2;j < i;j++)
if(i % j == 0)
{
a = 0;
break;
}
if(a==1)
lstPrime.Items.Add(i);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?