Idea: first analysis and judgment, the entire program is repeated input numbers, so the whole process is in a dead loop statement, which is the use of a whil statement, the condition is true, followed by the user input of the number of the judgment, the removal of less than equals 2 and greater than 2 of the cardinality, The rest of the numbers will satisfy the condition; then find a prime number between 1-input I; this is the definition of a k,k equals input-i; then I, if I is also a prime number, can output input=i+k, and finally complete the calculation. (When coding too much, it's best to create intervals to separate them, which is easy to parse and get wrong)
The code is as follows:
while (true)
{
Console.Write ("Please enter an even number greater than 2:");
int input = Int. Parse (Console.ReadLine ());
#region \ \ Remove the number less than or equal to 2
if (Input <= 2)
{
Console.Write ("Input is wrong, please press ENTER to re-enter!") ");
Console.ReadLine ();
Console.clear ();
}
#endregion
Else
{
#region//Remove cardinality
if (input% 2! = 0)
{
Console.Write ("Input is wrong, please press ENTER to re-enter!") ");
Console.ReadLine ();
Console.clear ();
}
#endregion
Else
{
for (int i = 2; i < (INPUT/2) +1; i++)
{
BOOL Falg = false;
for (int j = 2; J < I; J + +)
{
if (i% j = 0)
{
Falg = true;
}
}
if (!FALG)
{
int k = input-i;
if (k>1) {
BOOL ABC = FALSE;
for (int x = 2; x < K; × x + +)
{
if (k% x = = 0)
{
ABC = TRUE;
}
}
if (!ABC)
{
Console.Write (input + "=" + i + "+" + K);
Console.ReadLine ();
Console.clear ();
}
}
}
}
}
}
}
Complete Goldbach conjecture with control statement in C # (an even number greater than two must be the sum of two prime numbers)