Advertisement
Guest User

Untitled

a guest
May 9th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApp5
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int input = int.Parse(Console.ReadLine());
  11.  
  12.            // string arrString = "";
  13.  
  14.             int[] arr = new int[input];
  15.             int counter = 0;
  16.  
  17.             for (int i = 2; i <= input; i++)
  18.             {
  19.                 bool isPrime = true;
  20.  
  21.                 for (int j = 2; j <= Math.Sqrt(i); j++)
  22.                 {
  23.                     if (i % j == 0)
  24.                     {
  25.                         isPrime = false;
  26.                     }
  27.                 }
  28.  
  29.                 if (isPrime)
  30.                 {
  31.                     arr[counter] = i;
  32.                     counter++;
  33.                 }
  34.  
  35.             }
  36.  
  37.             Array.Resize(ref arr, counter);
  38.  
  39.             //  int[] arr = arrString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  40.  
  41.             Console.WriteLine(string.Join(" ", arr));
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement