So I am trying to make something to figure out prime numbers but my program thinks EVERYTHING is not prime. Does anyone know why? EDIT I guess I should have elaborated more on that I was trying to accomplish, I have three vars, two witch it multiplies together and the if questions ask if it is greater than C if this was the situation it would write it down as prime (I already see some mistakes made I am fixing it) And if at some point in time A times B equaled C (C Being the number we are trying to figure out is prime or not) It would be written as prime
namespace ConsoleApplication3
{
class Program
{
const string fileName = "NotPrime.txt";
const string filnamePrime = "Prime.txt";
static void Main(string[] args)
{
var c = 2;
var a = 1;
var b = 1;
while (true)
{
if (a * b == 1)
{
a = a + 1;
}
if ((a * b == c) && (c != 1))
{
Console.WriteLine("{0} is not prime.", c);
using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
writer.Write(string.Format("{0}\r\n", c));
}
a = a = 1;
b = b = 1;
c = c + 1;
}
if ((a * b != c) && (c * b > c))
{
Console.WriteLine("{0} is prime.", c);
using (BinaryWriter writesr = new BinaryWriter(File.Open(filnamePrime, FileMode.Create)))
{
writesr.Write(string.Format("{0}\r\n", c));
}
a = a = 1;
b = b = 1;
c = c + 1;
}
if (a * b < c)
{
b = b + 1;
a = a = 1; // This is causing everything to mess up here but I know it will be nessesary once I figure out how to fix this current error.
}
Thread.Sleep(1000);
}
}
}
}