// static void Main(string[] args) { int n = 1, i = 0, div = 0, sum = 0, x, y=0; for (i = 1; i <= 20; i++) { for (n = 1; n <= 500; n++) { for (x = 1; x <= n; x++) { if (n % x == 0) { div++; } } if (div == 2) { sum=sum+n; y++; } div = 0; if (y == 20) { break; } } } Console.WriteLine("prime sum:" + sum); Console.ReadKey(); } }}
// static void Main(string[] args) { int n = 1, i = 0, div = 0, sum = 0, x, y=0; for (i = 1; i <= 20; i++) { for (n = 1; n <= 500; n++) { for (x = 1; x <= n; x++) { if (n % x == 0) { div++; } } if (div == 2) { Console.WriteLine(n); y++; } div = 0; if (y == 20) { break; } } } Console.ReadKey(); } }}