C#计算质数

来源:百度知道 编辑:UC知道 时间:2024/05/04 09:23:44
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public bool isjs(int b)
{
int intm;
for (int a = 2; a <= b - 1; a++)
{
intm = b % a;
if (intm == 0)
{
return false;
}
}
return true;
}
private void button1_Click(object sender, EventArgs e)
{
int intm;
int intjg = 0;
label2.Text="所有质数为";
bool intbs = false;

c# 一个算质数的小程序,可以找出一定范围内的质数,可以求质数的个数,与打印所有质数。

也许以后能用到,存档先。

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Date1223_3
...{
class PrimeNum
...{
public static void Main(String[] args)
...{
bool div = false;
ArrayList list = new ArrayList();

Console.WriteLine("输入你想要算质数的范围:");
int range = Int32.Parse(Console.ReadLine());
Console.WriteLine("你想要算出{0}以内的质数,点Enter计算",range);
Console.ReadLine();

for (int i = 2; i < range+1; i++)
...{
div = false;
for (int j = 2; j < i; j++)
...{
if (i % j == 0)
...{
div = true