Train of Thought Analysis:1) First, determine the number of prime numbers. A prime number is a number that can be divisible by 1 and itself, but cannot be divisible by a number smaller than 1;
2) 2 is the smallest prime number and the only prime number that can be divisible by 2;
3) All the even numbers except 2 are not prime numbers.
In C #, we usually write the following program:
// Find the prime number between 1 and 100.
Console. Write (2 + "");
For (int x = 3; x <= 100; x + = 2) // if it is an even number, do not consider
{
Bool flag = true; // The dozens of prime numbers to be judged by default
If (x % 2 = 0)
{
Flag = false;
}
Else
{
For (int I = 3; I <x/2; I + = 2)
{
If (x % I = 0)
{
Flag = false;
Break;
}
}
}
If (flag = true) // the number currently determined is indeed a prime number.
{
Console. Write (x + ""); // Add a space to the end of x.
}
}
Console. WriteLine ();
For many masters, this may be as simple as "1 + 1 = 2", but for a beginner like me, I have to worry about it! Come on, Ajax girl! 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/20362V3R-0.gif "/>
This article is from the "Ajax girl" blog!