I need to make a GUI application that checks prime numbers when the user input two numbers. The criteria is that I make two methods, one that checks if a number is prime and that is my isPrime(int n)
and another that checks which of the two inputs is lower/higher so that the program knows where to start.
I can't manage to do this. When I run the script I don't have any output in Listbox.
My code so far:
private void button1_Click(object sender, EventArgs e)
{
int num1, num2;
num1 = Int32.Parse(textBox1.Text);
num2 = Int32.Parse(textBox2.Text);
for (int i = num1; i <= num2; i++) //Method that checks which of the two inputs is lower/hihger
{
if (isPrime(i))
{
for (int j = 2; j <= 1 / 2; j++)
{
if (i % j == 0)
{
break;
}
}
if (i == 0 && i != 1)
{
listBox1.Items.Add(i);
}
}
}
}
private static bool isPrime(int n) //Method to check prime numbers
{
for (int i = 2; i < n; i++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}