tanya_zheleva

04

Jan 31st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ExamPreparation
  6. {
  7.     class Startup
  8.     {
  9.         static void Main()
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             List<int> primes = new List<int>();
  13.             bool isPrime = true;
  14.  
  15.             for (int i = 2; i <= n; i++)
  16.             {
  17.                 for (int k = 2; k <= (int)Math.Sqrt(i); k++)
  18.                 {
  19.                     if (i % k == 0)
  20.                     {
  21.                         isPrime = false;
  22.                     }
  23.                 }
  24.  
  25.                 if (isPrime)
  26.                 {
  27.                     primes.Add(i);
  28.                 }
  29.  
  30.                 isPrime = true;
  31.             }
  32.  
  33.             Console.WriteLine(string.Join(" ", primes));
  34.         }
  35.     }
  36. }
Add Comment
Please, Sign In to add comment