C# 判断一个数是否是素数

来源:百度知道 编辑:UC知道 时间:2024/05/10 10:25:09
为什么不对呢??
using System;
namespace Demo
{
public class sushu
{
public sushu()
{
while(1==1)
{
Console.WriteLine("请输入一个正整数");
string x=Console.ReadLine();
int a=int.Parse(x);
if(x=="e"||x=="E")
{
break;
}
else
{
bool yes=false;
yes=false;
for(int i=2;i<Math.Sqrt(a);i++)
{
if(a%i==0)
{
yes=true;
}
else
{
yes=false;
}
}
if(yes)
{
Console.WriteLine(x+"不是素数");
}
else
{
Console.WriteLine(x+"是素数");
}
}
}
}
}
}

using System;

namespace ch03_1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
for(;;)
{
Console.WriteLine("请输入一个数");
string s=Console.ReadLine();
uint i=uint.Parse(s);
int j=2;

for(;j<i;j++)
{
if(i%j==0)
{
break;
}
}
if(i==j)
{
Console.WriteLine("是");
}
else
{
Console.WriteLine("不是");
}
}

}
}
}

这是我写的,看下.能行不.

没有程序入口点
把public sushu() 改成 static void Main() 就可以了
static void Main() 是程序入口点