using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int a = 0; for(int s=0;s<=100;s++) { int num = 0;//记录能整除的数的个数 for (int i = 1; i <= s; i++) { if (s % i == 0) { num++; } } if (num == 2) { Console.WriteLine(s); a = a + s; } } Console.WriteLine("100以内所有质数和为{0}",a); Console.ReadLine(); } } }