Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace SieveOfEratosthenes
- {
- class Program
- {
- static void Main(string[] args)
- {
- var n = int.Parse(Console.ReadLine());
- List<int> sequnceOfPrimeNumbers = new List<int>();
- var isPrime = false;
- for (int i = 2; i <= n; i++)
- {
- isPrime = CheckForPrimeNumberInSequence(i);
- if (isPrime)
- {
- sequnceOfPrimeNumbers.Add(i);
- }
- }
- Console.WriteLine(string.Join(" ", sequnceOfPrimeNumbers));
- }
- private static bool CheckForPrimeNumberInSequence(int n)
- {
- bool isPrime = true;
- for (int i = 2; i <= Math.Sqrt(n); i++)
- {
- if (n % i == 0)
- {
- isPrime = false;
- break;
- }
- }
- return isPrime;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement