I'm trying to find if a number is prime using C#. I have written the code. It should work but for some reason it doesn't seem to.
This is my code (I've tried inputting 7, 13 etc, says they are not prime):
class Program
{
static void Main(string[] args)
{
long u = Console.Read();
primefinder(u);
Console.ReadLine();
}
private static void primefinder(long a)
{
long counter = 0;
for (long b = 1; b <= a; b++)
{
if ((a % b) == 0)
{
counter++;
}
}
if (counter == 2)
{
Console.WriteLine("Is prime!");
}
else
{
Console.WriteLine("Is not prime");
}
Console.ReadLine();
}
}