Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class PrimesInGivenRange
- {
- static void Main()
- {
- int startNumber = int.Parse(Console.ReadLine());
- int endingNumber = int.Parse(Console.ReadLine());
- PrintAListOfIntegers(FindPrimesInRange(startNumber, endingNumber));
- }
- static List<int> FindPrimesInRange(int startNum, int endNum)
- {
- List<int> list = new List<int>();
- bool answer;
- for (int i = startNum; i <= endNum; i++)
- {
- answer = true;
- for (int j = 2; j < i; j++)
- {
- if (i % j == 0)
- {
- answer = false;
- break;
- }
- }
- if (answer == true && i > 1)
- {
- list.Add(i);
- }
- }
- return list;
- }
- static void PrintAListOfIntegers(List<int> list)
- {
- Console.WriteLine(string.Join(", ", list));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement