Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class FindPrimes
- {
- static void Main()
- {
- int countPrimes = 1;
- int number = 3;
- while (countPrimes < 251)
- {
- bool isPrime = true;
- for (int divisor = 2; divisor <= Math.Sqrt(number); divisor++)
- {
- if (number % divisor == 0)
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime)
- {
- countPrimes++;
- if (countPrimes == 24 || countPrimes == 101 || countPrimes == 251)
- {
- Console.WriteLine(
- "The {0}{1} prime number is: {2}",
- countPrimes, countPrimes == 24 ? "th" : "st", number);
- }
- }
- number++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement