static void Main(string[] args)
{
int i, count = 0;
for (i = 2; i <= 100; i++)
{
if (primeNum(i))
{
Console.Write("{0} ", i);
count++;
if (count % 5 == 0)
{
Console.WriteLine();
}
}
}
}
public static bool primeNum(int n)
{
int i, flag = 0;
bool ye;
for (i = 2; i < n; i++)
{
if (n %i == 0)
{
flag = 1;
break;
}
else
flag = 0;
}
if (flag == 0)
ye = true;
else
ye = false;
return ye;
}
for (int i=2 ; i<=100 ;i++)
{
int count = 0;
for (int j= 2; j<= Math.Sqrt(i); j++)
{
if (i % j != 0)
{
continue;
}
count++;
}
if (count == 0)
{
Response.Write(i.ToString()+" ");
}
}
楼上正解
答案很好,我很满意