To determine the prime number, you can open the given number and use this value to divide the number from 1 to open the house or only the largest integer smaller than the given one. If the number cannot be divisible, this is a prime number, otherwise, it is not a prime number.
Next, create a console application, enter the number to be judged in the console, use the int type variable record, and then determine whether the input number is a prime number. The prompt message is displayed. The code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace JudgePNum
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("Enter the number to be judged:"); // the system prompts you to enter the information.
Int j = 0; // defines an int variable to record the maximum number after the square root of the input number.
Int intNum = Convert. ToInt32 (Console. ReadLine (); // records the number of inputs;
J = (int) Math. Ceiling (Math. Sqrt (Convert. ToDouble (intNum); // assign a value to j,
// CEILING (number, significance), rounds up the parameter Number (in the direction of increasing the absolute value) to a multiple of the nearest significance
// Sqrt (number) returns the square root of the value.
Int intFlag = 0;
For (int I = 2; I <j; I ++)
{
IntFlag + = Convert. ToInt32 (Math. IEEERemainder (intNum. I); // returns and records
}
If (intFlag = 0) // Determine whether the remainder is 0
Console. WriteLine (intNum + "is not a prime number. ");
Else
Console. WriteLine (intNum + "is a prime number. ");
Console. ReadLine ();
}
}
}