Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. The smallest prime number is 2, since its only divisors are 1 and 2.
- // The prime number at position 1 is: 2
- // http://www.geocachingtoolbox.com/index.php?page=primeNumbers
- Console.WriteLine("Prime numbers:");
- bool isPrime = true;
- for (i = 2; i < 100; i++)
- {
- isPrime = true;
- for (int j = 2; j < i; j++)
- {
- // if (i % j == 0)
- if (i % Math.Sqrt(j) == 0) // better
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime) {
- Console.WriteLine(i);
- }
- }
Add Comment
Please, Sign In to add comment