Prime number. In a natural number greater than 1, except for 1 and the integer itself, it cannot be divisible by other natural numbers. Or among all integers greater than 1, except 1 and itself, there are no other factors. Such integers are called prime numbers or prime numbers. In other words, only the natural numbers of two positive factors (1 and itself) are prime numbers. A number larger than 1 but not a prime number is called a union number. 1 and 0 are both non-prime numbers and non-composite numbers. Prime numbers play an important role in number theory.
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace Sushu
{
Class Program
{
Static void main (string [] ARGs)
{
Int statue = 0;
Console. writeline ("output all prime numbers of 1-10000 ");
For (INT I = 2; I <= 10000; I ++)
{
For (Int J = 2; j <I; j ++)
{
If (I % J = 0)
{
Statue = 0;
Break; // jump out of this loop
}
Else
{
Statue = 1;
}
}
If (statue = 1)
{
Console. Write (I + "");
}
}
Console. Readline ();
}
}
}
Method 2:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace zhishu
{
Class Program
{
Static void main (string [] ARGs)
{
Int state = 0;
Int I;
Console. writeline ("output prime numbers between 1 and ");
For (I = 2; I <= 100; I ++)
{
For (Int J = 2; j <math. SQRT (I); j ++)
{
If (I % J = 0)
{
State = 0;
Break;
}
Else
{
State = 1;
}
}
If (State = 1)
{
Console. Write (I + "");
}
}
Console. readkey ();
}
}
}
The second method is more efficient.