Advertisement
Monteso

Untitled

Dec 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _07.Primes_in_Given_Range
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var startNum = long.Parse(Console.ReadLine());
  14.             var endNum = long.Parse(Console.ReadLine());
  15.             var primeList = " ";
  16.             //IsPrime(startNum, endNum, primeList);
  17.         }
  18.  
  19.         static void IsPrime(long startNum, long endNum, string primeList)
  20.         {
  21.             for (long i = startNum; i <= endNum; i++)
  22.             {
  23.                 var prime = true;
  24.  
  25.                 if (i <= 1)
  26.                 {
  27.                     prime = false;
  28.                 }
  29.  
  30.                 for (var j = 2; j <= Math.Sqrt(i); j++)
  31.                 {
  32.                     if (i % j == 0)
  33.                     {
  34.                         prime = false;
  35.                         break;
  36.                     }
  37.                 }
  38.                 if (prime)
  39.                 {
  40.                     Console.Write($"{i}, ");
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement