Advertisement
Guest User

Untitled

a guest
Apr 6th, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class PrimesInGivenRange
  5. {
  6.         static void Main()
  7.         {
  8.             int startNumber = int.Parse(Console.ReadLine());
  9.             int endingNumber = int.Parse(Console.ReadLine());
  10.             PrintAListOfIntegers(FindPrimesInRange(startNumber, endingNumber));
  11.         }
  12.         static List<int> FindPrimesInRange(int startNum, int endNum)
  13.         {
  14.             List<int> list = new List<int>();
  15.             bool answer;
  16.             for (int i = startNum; i <= endNum; i++)
  17.             {
  18.                 answer = true;
  19.                 for (int j = 2; j < i; j++)
  20.                 {
  21.                     if (i % j == 0)
  22.                     {
  23.                         answer = false;
  24.                         break;
  25.                     }
  26.                 }
  27.                 if (answer == true && i > 1)
  28.                 {
  29.                     list.Add(i);
  30.                 }
  31.             }
  32.             return list;
  33.         }
  34.         static void PrintAListOfIntegers(List<int> list)
  35.         {
  36.             Console.WriteLine(string.Join(", ", list));
  37.         }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement