Advertisement
dkeray

Eratosthenes Prime Numbers

Jan 13th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class EratosthenesPrimeNumbers
  6. {
  7.     static void Main()
  8.     {
  9.         List<int> num = new List<int>();
  10.  
  11.         num.Add(2);
  12.         num.Add(3);
  13.         num.Add(5);
  14.         for (int i = 6; i <=  10000000; i++)
  15.         {
  16.  
  17.             if ((i % 2 == 0) || (i % 3 == 0) || (i % 5 == 0))
  18.             {
  19.                 continue;
  20.             }
  21.             else num.Add(i);
  22.         }
  23.  
  24.         for (int i = 0; i < num.Count; i++)
  25.         {
  26.             if (i % 15 == 0) Console.WriteLine();
  27.             Console.Write("{0,9}", num[i]);
  28.            
  29.         }
  30.         Console.WriteLine();
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement