首先定义布尔型数组初始值为false,先改变下标为2的倍数的值为true,再改变下标为3的值为true,以此类推,剩下为fasle数组下标即为质数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace PrimeNumber
{
class Program
{
static void Main(string[] args)
{
const int MAX = 300;
//false为质数,true为非质数
//申明后若没有给定初值,其默认值为false
bool[] prime = new bool[MAX];
prime[0] = true;
prime[1] = true;
int num = 2, i;
while (num < MAX)
{
if (!prime[num])
{
for (i = num + num; i < MAX; i += num)