Advertisement
Martichka

C# Arrays/ Task - 15 Prime Numbers

Jan 21st, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2.  
  3. class SieveOfEratosthenes
  4. {
  5.     static void Main()
  6.     {
  7.         int[] nums = new int[10000000];
  8.         for (int i = 0; i < nums.Length; i++)
  9.         {
  10.             nums[i] = i + 1;
  11.         }
  12.         for (int index = 0; index < nums.Length; index++)
  13.         {
  14.             for (int check = 2; check <= nums[index]; check++)
  15.             {
  16.                 bool checking = nums[index] % check == 0;
  17.                 if (checking == true && (check == nums[index]))
  18.                 {
  19.                     Console.WriteLine(nums[index]);
  20.                 }
  21.                 else if (checking == true && (check != nums[index]))
  22.                 {
  23.                     break;
  24.                 }
  25.                 else if (checking == false)
  26.                 {
  27.                     if (check <= nums[index])
  28.                     {
  29.                         continue;
  30.                     }
  31.                     else if (check == nums[index])
  32.                     {
  33.                         Console.WriteLine(nums[index]);
  34.                     }
  35.                 }
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement