SteelGolem icon

finding primes up to 65535

SteelGolem | PRO | 07/30/20 11:35:22 PM UTC | 0 ⭐ | 1706 👁️ | Never ⏰ | []
C# |

680 B

|

None

|

0 👍

/

0 👎

 
using System;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // 1 2 3 are primes
            int numPrimes = 3;
 
            for (int num = 4; num < 65535; num++)
            {
                if (IsPrime(num)) { Console.WriteLine(num + " is a prime number."); numPrimes++; }
            }
            Console.WriteLine("there were " + numPrimes + " primes.");
            Console.ReadKey();
        }
 
        static bool IsPrime(int value)
        {
            for (int i = 2; i < value - 1; i++) if (value % i == 0) return false;
 
            return true;
        }
    }
}
 

Comments