int[] su = new int[10];
int[] num = new int[10];
Console.WriteLine("请连续输入10个数1-1000的整数,用空格隔开");
string strNum = Console.ReadLine();
string[] str=strNum.Split(' ');
for (int i = 0; i < str.Count(); i++)
{
num[i] = Convert.ToInt32(str[i]);
}
for (int i = 0; i < num.Count(); i++)
{
int count = 0;
for (int j = 2; j <= Math.Sqrt(num[i]); j++)
{
if (num[i] % j == 0)
{
count++;
}
}
if (count == 0)
{
su[i] = num[i];
}
}
Console.WriteLine("其中素数是:");
int sum=0;
for (int i = 0; i < su.Count(); i++)
{
Console.Write("{0} ", su[i]);
sum += su[i];
}
Console.WriteLine();
Console.WriteLine("素数和为:" + sum);
Console.ReadKey();