{
int num =0;
List
string f = Console.ReadLine();
while (f != "0")
{
if (int.TryParse(f, out num))
{
mylist.Add(num);
}
else
{
Console.WriteLine("输入无效");
}
f = Console.ReadLine();
}
Console.WriteLine("您输入的一组整数为:"+string.Join(",",mylist));
List
List
for (int i = 0; i < mylist.Count; i++)
{
if(mylist[i]>1)
{
if (isprime(mylist[i]) == 1)
{
lstPrime.Add(mylist[i]);
}
else
{
lstNumber.Add(mylist[i]);
}
}
}
Console.WriteLine("其中素数为:" + string.Join(",", lstPrime));
Console.WriteLine("合数为:" + string.Join(",", lstNumber));
Console.ReadLine();
}
///
/// 判别是否为素数
/// </summary>
/// </param>
///
public static int isprime(int num)
{
if (num == 1) return 0;
for (int i = 2; i <=Math.Sqrt(num); i++)
{
if (num % i == 0)//如果为0,则不是素数
{
return 0;
}
}
return 1;
}