Class2.cs
[sourcecode language=”c” title=”Class2.cs”]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Class2
{
static void Main(string[] args)
{
Console.WriteLine("整数1不是素数!");
for (int m = 2; m<= 100; m++) {
bool flag = true;
int k = (int)(Math.Sqrt(m));
int i = 2;
while (i <= k && flag == true)
{
if (m % i == 0) flag = false;
else i++;
}
if (flag == true)
Console.WriteLine("整数{0}是素数!", m);
else
Console.WriteLine("整数{0}不是素数!", m);
}
Console.ReadKey();
}
}
}[/sourcecode]
效果图: